solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:100000000")
using namespace std;
template <class T>
void read(T &x) {
char c, mi = 0;
while (c = getchar(), c <= 32)
;
if (c == '-')
mi = 1, x = 0;
else if (c < 48 || c > 57)
return void(x = c);
else
x = c - 48;
while (c = getchar(), c... | 5 |
#include <bits/stdc++.h>
const int N = 500010;
const int inf = 0x3f3f3f3f;
using namespace std;
int n, m;
int vis[N];
bool q[N];
set<int> st;
int l[N];
vector<int> vt[N], ret[N];
int main() {
scanf("%d%d", &n, &m);
for (int i = 0; i < m; i++) {
int a, b;
scanf("%d%d", &a, &b);
vt[a].push_back(b);
vt... | 5 |
#include <bits/stdc++.h>
using namespace std;
string str, str1;
int main() {
int k, n, i, cnt, len, j;
cin >> str >> k;
len = str.size();
cnt = 0;
for (i = 0; i < len; i++)
if (str[i] != '?' && str[i] != '*') cnt++;
for (i = 1, str += '~'; i < str.size(); i++) {
if (str[i] == '?') {
if (cnt > ... | 3 |
#include<bits/stdc++.h>
using namespace std;
#define eps (1e-8)
int N,M;
double L;
double P[100],T[100],V[100];
double a[100][100],b[100][100];
double mem[100][100];
double ncr(int n,int r){
if(mem[n][r]!=-1.0)return mem[n][r];
r=min(r,n-r);
double res=1.0;
for(int i=0;i<r;i++){
res=res*(double)(n-i);
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long UNO = 1LL;
const long long DOS = 2LL;
const long long CERO = 0LL;
long long fun(pair<long long, long long> p1, pair<long long, long long> p2,
pair<long long, long long> p3, pair<long long, long long> p4) {
long long a = CERO, b = CERO;
if (... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e2 + 7;
int n, V, m, a[N], b[N], c[N][N], vis[N], deg[N];
vector<int> e[N];
void addEdge(int u, int v) {
++deg[u], ++deg[v];
e[u].push_back(v), e[v].push_back(u);
}
void dfs(int u) {
vis[u] = true;
for (int i = (1); i < (n + 1); ++i)
if (c[u][i] &... | 5 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops")
using namespace std;
const int N = (int)1e6;
map<char, int> nxt[N];
vector<pair<int, int> > items[N];
int who[N];
int tot, n = 1;
long long ans = 0;
void add(string& s, int c, int idx) {
int v = 0;
for (auto c : (s)) {
if (!nxt[v].count(c)) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pl;
pl v[200200];
multiset<ll> rb,bb;
int main() {
ios::sync_with_stdio(0);cin.tie(0);
int n;
cin >> n;
for(int i=0;i<n;i++) {
ll a,b;
cin >> a >> b;
if(a > b) {swap(a,b);}
v[i] = {a,b};
rb.insert(a);
bb.insert(b);
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 666;
typedef int flow_t;
typedef long long cost_t;
const flow_t flow_inf = 1e9;
const cost_t cost_inf = 4e18;
namespace flow {
struct edge {
int to, rev;
flow_t cap;
cost_t cost;
edge(int _to, int _rev, flow_t _cap, cost_t _cost)
: to(_to), r... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void chkmax(T &a, T b) {
if (a < b) a = b;
}
template <class T>
void chkmin(T &a, T b) {
if (a > b) a = b;
}
const int p = 1e9 + 7;
int fac[1000010], rfac[1000010], inv[1000010];
void prepare() {
fac[0] = rfac[0] = fac[1] = rfac[1] = inv[1] = 1;
f... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e4;
int main() {
int tt;
cin >> tt;
while (tt--) {
int n;
cin >> n;
int f[N] = {0};
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
int s = a[i];
for (int j = i +... | 5 |
#include <bits/stdc++.h>
using namespace std;
double pi = acos(-1);
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
long long powerm(long long a, long long b, long long m) {
if (b == 0) return 1;
if (b & 1) return a * powerm(a * a % m, b / 2, m) % m;
return powerm(a * a % m, b / 2, m... | 4 |
#include <bits/stdc++.h>
using namespace std;
string ans;
long long d, x;
void check(string s) {
long long val, i;
val = 0;
for (i = 0; i < s.length(); i++) val = val * 10 + (char)(s[i] - '0');
if ((x - val <= d) && (x - val >= 0)) ans = s;
}
int main() {
long long i, j, flag;
string s;
x = 0;
cin >> s ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n = 0, k = 0;
cin >> n >> k;
int d = 5 - k;
vector<int> arr;
int x;
for (int i = 0; i < n; i++) {
cin >> x;
arr.push_back(x);
}
sort(arr.begin(), arr.end());
int team = 0;
for ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 252;
int dis(int x1, int y1, int x2, int y2) { return abs(x1 - x2) + abs(y1 - y2); }
bool Gao(int x1, int y1, int x2, int y2) {
if (dis(0, 0, x1, y1) <= max(x2, y2)) return true;
for (int i = 1; i <= min(x2, y2); ++i) {
if (dis(x2 - i, y2 - i, x1, y1) ... | 3 |
#include<iostream>
#include<vector>
#include<string>
using namespace std;
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
int main(){
string s;
cin>>s;
int co[260]={0};
rep(i,s.size())co[s[i]]++;
int out=0;
rep(i,260){
if(co[i]){
int cnt=0;
int j=i;
while(co[j])j+... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
map<int, int> br;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
br[a]++;
}
int broj = 0;
for (int i = 200001; i >= 0; i--) {
int d = br[i];
if (d == 0) continue;
if (d == n) {
break;
}
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
bool ans=false;
for(int i=0;i<N;i++){
char c;
cin >> c;
if(c=='Y')ans=true;
}
if(ans)cout << "Four";
else cout << "Three";
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main(){
string s; cin >> s;
vector<string> day={"SUN","MON","TUE","WED","THU","FRI","SAT"};
for(int i=0;i<7;i++){
if(day[i]==s) cout << 7-i;
}
} | 0 |
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:64000000")
using namespace std;
int n;
vector<int> a, b, r;
vector<int> inv(vector<int>& a) {
vector<int> res(n);
for (int i = 0; i < int(n); i++) res[a[i]] = i;
return res;
}
vector<int> mul(vector<int>& a, vector<int>& b) {
vector<int> res(n);
for (in... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const long long BIG = 1446803456761533460LL;
const int Big = 336860180;
const int INF = INT_MAX;
const vector<vector<int> > adj4({{0, 1}, {0, -1}, {1, 0}, {-1, 0}});
const vector<vector<int> > adj8(
{{0, 1}, {0, -1}, {1, 0}, {-1, 0}, {-1, -1}... | 5 |
#include <bits/stdc++.h>
using namespace std;
string a, b, c, d, s = "", t = "";
void change() {
if (a[0] == 'X')
swap(a[0], b[0]);
else if (b[0] == 'X')
swap(b[0], b[1]);
else if (b[1] == 'X')
swap(b[1], a[1]);
else if (a[1] == 'X')
swap(a[1], a[0]);
}
int main() {
cin >> a >> b >> c >> d;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, m;
cin >> n >> m;
long long int k, l;
long long int ans = 0;
vector<long long int> vx, vy;
for (long long int i = 2; i <= 100000; i += 2) {
k = n - i + 1;
l = m - i + 1;
if (k > 0) vx.push_back(k);
if (l > 0) vy.push... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int q;
cin >> q;
while (q--) {
int n;
cin >> n;
string s;
cin >> s;
if (s.length() == 2) {
if (s[0] >= s[1]) {
cout << "NO\n";
continue;
} else {
cout << "YES\n";
cout << "2\n";
cout ... | 1 |
#include <bits/stdc++.h>
const long long T00B1G = 9223372036854775807LL;
const int maskl = 5;
bool mask[64][5];
template <class TEl>
using TTable = std::vector<std::vector<TEl>>;
template <class TEl>
void spacecreator(long long first, long long second, TTable<TEl>& vec) {
vec.resize(first);
for (auto& sub : vec) {
... | 5 |
#include <bits/stdc++.h>
#pragma GCC optimize("-O3")
using namespace std;
long long MOD = 1e9 + 7;
long long mpow(long long a, long long b) {
if (b >= (MOD - 1)) b %= (MOD - 1);
if (b == 0) return 1;
long long t1 = mpow(a, b / 2);
t1 *= t1;
t1 %= MOD;
if (b % 2) t1 *= a;
t1 %= MOD;
return t1;
}
long lon... | 4 |
#include <bits/stdc++.h>
using namespace std;
char a[100005];
char b[100005];
int main() {
int n;
while (~scanf("%d", &n)) {
scanf("%s%s", a, b);
int tt[4];
int sum = 0;
for (int i = 0; i < n / 2; i++) {
int sum1 = 1;
map<int, int> m;
m.clear();
int book[5] = {0};
tt[0]... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
string a, b;
int mmap1[200005][27], mmap2[27];
int xuhao(char a) { return a - 'a' + 1; }
bool pd(int mid) {
for (int i = 1; i <= 26; i++) {
if (mmap1[mid][i] < mmap2[i]) {
return false;
}
}
return true;
}
int main() {
cin >> n >> a >> m;
fo... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int Maxn = 1e5 + 2;
int n, k, i, j, sum;
struct Mod_10 {
int x, rest;
bool operator<(const Mod_10 &b) const {
return rest < b.rest || (rest == b.rest && x < b.x);
}
} a[Maxn];
int main() {
scanf("%d %d", &n, &k);
for (i = 0; i < n; i++) {
scanf("%d",... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 500005;
int n, x, y;
int head[N], nxt[2 * N], tail[2 * N];
int f[N][2];
vector<int> g[2][N];
struct xxx {
int a, b, c, d;
} ans[N];
int cnt;
int s[N];
int gf(int k) {
if (s[k] != k) s[k] = gf(s[k]);
return s[k];
}
bool check(int u, int x, int y) {
if (... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t, n, x, k;
cin >> t;
while (t--) {
set<int> s;
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> x;
s.insert(x);
}
if (s.size() > k) {
cout << -1 << ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int p = 517;
const int MAXN = 10000 + 228;
int ppow[MAXN];
int hsh[MAXN];
void init_hashes(string s) {
int n = s.size();
ppow[0] = 1;
for (int i = 0; i < n; i++) {
ppow[i + 1] = 1LL * ppow[i] * p % MOD;
hsh[i + 1] = (1LL * hsh[i]... | 3 |
#include <bits/stdc++.h>
using namespace std;
std::mt19937 rng(
(int)std::chrono::steady_clock::now().time_since_epoch().count());
const int MOD = 1000000007;
const int MAXN = 100010;
vector<int> adj[MAXN];
int dad[MAXN];
bool diameter[MAXN];
bool used[MAXN];
int dist[MAXN];
int n;
int mxU, mxV;
void dfs(int u, int... | 2 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
using namespace std;
const int mod = 1000000007;
const long double DOUBLE_MAX = DBL_MAX;
inline bool vowel(char c) {
if (... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 200007;
const int MAX = 500007;
int n, m, kp;
int a[MAXN];
int op[MAXN];
bool isp[MAX];
int prm[MAX];
bool in[MAX... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100 + 19, M = 5000 + 19;
const double eps = 1e-9;
struct Edge {
int x, y, f;
} E[M * 2];
typedef double Matrix[N][N];
int n, m, x, y, f, tot;
double Ans, tmp;
Matrix A;
void Gauss() {
for (int i = 1; i <= n; i++) {
int r = i;
for (int j = i + 1; j ... | 3 |
#include<bits/stdc++.h>
using namespace std;
#define int long long
int dp[3010];
// kmjp参照
const int MOD = 998244353;
void modadd(int &a, int b){
a = (a+b)%MOD;
}
signed main(void){
int n,S; cin >> n >> S;
int ans =0 ;
for(int i = 0; i < n; i++){
int x; cin >> x;
for(int j = S-x; j >= 0; ... | 0 |
#include <cstdio>
const int MAXN=311, MAXA=311;
const int MOD=998244353;
inline int sum(const int &a, const int &b){
return (a+b>=MOD)?(a+b-MOD):(a+b);
}
inline int mul(const int &a, const int &b){
return (int)((1LL*a*b)%(long long)(MOD));
}
int pow(int a, int k){
int r=1;
while(k){
if(k&1) r=mul(r, a);
a=m... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[120][120];
int t, k, l, o;
int ops;
int main() {
cin >> n >> m;
for (int j, i = 0; i < n; ++i) {
for (j = 0; j < m; ++j) {
if (a[i][j] != 0) {
continue;
}
t = 'A';
if (i > 0 && a[i - 1][j] == t) {
++t;
}
... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, par[100005], dis[100005], dp[20][100005], vis[100005];
vector<long long> a[100005];
double cnt[100005], sum[100005], rootsum[100005];
void dfs(long long node) {
vis[node] = 1;
cnt[node] = 1;
for (auto i : a[node]) {
if (!vis[i]) {
par[i] = no... | 5 |
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int INF = 1e9;
int T, N;
vector<int> t;
int wktm[110], dp[110], nxt[110];
int ed;
signed main(){
while(cin >> T, T){
t.clear();
t.resize(T);
r... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
vector<int> p(n);
for(int i=0; i<n; i++)cin>>p.at(i);
int ans=0;
for(int i=0; i<n-1; i++){
if(p.at(i)==i+1){
swap(p.at(i), p.at(i+1));
ans++;
}
}
if(p.at(n-1)==n)ans++;
cout<<ans<<endl;
}
| 0 |
#include <iostream>
#include <cstdlib>
using namespace std;
int cnt;
string l,r;
void check(){
int x = atoi(l.c_str()) ,y = atoi(r.c_str());
if(l.size() > r.size() || x > y || l[0] == '0' || r[0] == '0') return;
if((x + y) % 2 == 0 || (x - y) % 2 == 0) cnt++;
}
int main(){
string a;
cin >... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, c = 0;
cin >> n;
char a[n];
int b[n];
cin >> a;
for (i = 0; i < n; i++) {
switch (a[i]) {
case '0':
b[i] = 0;
break;
case '1':
b[i] = 1;
}
if (b[i] == 1)
c++;
else {
c++;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
T abs(T x) {
return x > 0 ? x : -x;
}
int n;
int m;
double R, r;
int k;
int main() {
int tt;
scanf("%d", &tt);
for (int it = 0; it < tt; it++) {
scanf("%lf%lf%d", &R, &r, &k);
double a = 1 / R, b = 1 / r;
double h = (b - a) / 2;
do... | 5 |
#include <bits/stdc++.h>
using namespace std;
int x, y, n, m, ans;
bool done[7];
void dfs(int t, int p, int q) {
if (p >= n or q >= m) return;
if (t == x + y) {
ans++;
return;
}
for (int i = 0; i < 7; ++i) {
if (done[i]) continue;
int np = p, nq = q;
done[i] = true;
if (t < x)
np =... | 1 |
// C - GP 2
#include <bits/stdc++.h>
using namespace std;
#define MOD 998244353
struct FactTable {
vector<long long> a;
FactTable(int n) : a(n + 1, 1) { for (int i = 2; i < a.size(); i++) a[i] = a[i - 1] * i % MOD; }
inline long long operator()(int n) { return a[n]; }
} fact(2000000);
long long minv(long long a)... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1030;
string s[MAX_N];
int main() {
int n;
cin >> n;
int ctr = 0;
for (int i = 0; i < n; i++) {
cin >> s[i];
sort(s[i].begin(), s[i].end());
int A[128] = {0};
for (int j = 0; j < s[i].length(); j++) A[s[i][j]]++;
int cc = 0;
... | 1 |
#include<iostream>
#include<string>
using namespace std;
int main(){
int ans=-1,len=0;
string s;
while(getline(cin,s)){
while(1){
ans = s.find("the");
if(ans!=-1)break;
ans = s.find("this");
if(ans!=-1)break;
ans = s.find("that");
if(ans!=-1)break;
for(int i=0;i<s.siz... | 0 |
#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
long long int dp[302][302][302];
void add(long long int&x, long long int y){
x=(x+y)%mod;
}
vector<pair<int,int> > event[301];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n,m,k;
cin>>n>>m;
for(int i=1,l,r,x;i<=m;i++){
cin>>l>>... | 0 |
/*
* Author: aps
* Time: 19-06-2019 00:54:25
**/
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef ... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long int l,r;
int ans=2019;
int main()
{
cin>>l>>r;
if(r-l>=2019)
ans=0;
else
for(long long int i=l;i<=r;i++)
for(long long int j=l;j<i;j++)
{
int z=(i*j)%2019;
if(z<ans)
ans=z;
}
cout<<ans;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int T;
scanf("%d", &T);
for (int cs = 1; cs <= T; cs++) {
int n;
scanf("%d", &n);
int ar[n * 2 + 1], mark[n * 2 + 1];
memset(mark, 0, sizeof(mark));
for (int i = 0; i < n * 2; i++) scanf("%d", &ar[i]);
for (int i = 0; i < n * 2; i+... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5;
int n, m;
const int bsz = 330;
int parent[maxn], block_jump[maxn], num_block_jump[maxn];
void update(int a, int b) {
parent[a] = a + b;
int block = a / bsz;
int start_block = block * bsz;
int start_nxt_block = (block + 1) * bsz;
int curr = a;... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, t, nxt[N << 1], head[N], adj[N << 1], sz[N], fa[N], x, y;
double in[N], out[N], Sin, Sout, ans;
void push(int u, int v) {
nxt[++t] = head[u];
head[u] = t;
adj[t] = v;
}
void dfs(int u) {
sz[u] = 1;
for (int i = head[u]; i; i = nxt[i])... | 5 |
#include <bits/stdc++.h>
using namespace std;
ostream &operator<<(ostream &out, string str) {
for (char c : str) out << c;
return out;
}
template <class L, class R>
ostream &operator<<(ostream &out, pair<L, R> p) {
return out << "(" << p.first << ", " << p.second << ")";
}
template <class T>
auto operator<<(ostre... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const double eps = 1e-6;
int main(int argc, char** argv) {
ios_base::sync_with_stdio(false);
cin.tie(0);
string s;
cin >> s;
int a = 0, b = 0, c = 0, flag = 0, flag1 = 0, flag2 = 0;
for (int i = 0; i < s.size(... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, i, k, sum = 0, l;
cin >> n;
char s[1001];
char v[1001];
cin >> s;
cin >> v;
for (i = 0; i < n; i++) {
k = s[i] - 48;
l = v[i] - 48;
sum += min(abs(max(k, l) - min(k, l)), abs(max(k, l) - min(k, l) - 10));
}
cout <<... | 1 |
#include <bits/stdc++.h>
using namespace std;
double PI = acos(-1);
int const N = 5e5 + 10, M = 1e7 + 1, oo = 1e9;
const int mod = oo + 7;
const long long OO = 3e18;
int n, mrk[101][101];
char cc[101][101];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i = 0; i < n; i++) cin >> cc[i];
f... | 2 |
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
using namespace std;
#define FOR(i,k,n) for(int i=(k); i<(int)(n);... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 3e5 + 10;
int n;
vector<int> tree[N];
int s[N];
int f[N];
int h[N];
int hkx[N << 2];
int sk[N << 2];
int status = 0;
void dfs(int cur, int height) {
s[cur] = status;
h[cur] = height;
status += 1;
for (auto& e : tree[cur]) {
... | 5 |
#include <iostream>
using namespace std;
class dice{
public:
int d[7];
int setd();
int M(int*,int*,int*,int*);
};
int dice::setd(){
for(int i=1;i<=6;i++){
cin>>d[i];
}
return 0;
}
int dice::M(int *A,int *B,int *C,int *D){
int s,t;
s=*B;
*B=*A;
t=*C;
*C=s;
s=*D;
*D=t;
*A=s;
return 0;
}
int main(void){
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int INF = -1u / 2;
const int MAX_N = 1e5 + 5;
int n, m, d;
int ans;
int down[MAX_N][2];
bool spec[MAX_N];
vector<int> adj[MAX_N];
inline void dfs1(int u, int p = 0) {
down[u][0] = down[u][1] = spec[u] ? 0 : -INF;
for (int i = 0; i < adj[u].size(); i++) {
int v... | 2 |
#include<iostream>
using namespace std;
#define MOD 1000000007
long long N, L;
long long x[6000], a[6000];
long long dp[6000][6000];
int main() {
cin >> N >> L;
for (int i = 0; i < N; i++) { cin >> x[i]; }
for (int i = 0; i < N; i++) { cin >> a[i]; }
int cnt = 0;
for (int i = x[N - 1]; i < L; i += a[N - 1]) {
... | 0 |
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(... | 0 |
#include <iostream>
using namespace std;
int main(){
int n;
cin>>n;
n=n/100;
cout<<"ai1333";
for(int i=0;i<n;i++)cout<<"3";
cout<<endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int maps[9];
long long int N, K;
bool check() {
for (int i = 1; i <= K; i++) {
bool t = false;
for (int j = 0, k = i; j < 10; j++) {
k = maps[k];
if (k == 1) {
t = true;
break;
}
}
if (!t) return false;
}
return true;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
inline int qpow(int x, int n) {
x %= mod;
int ret = 1;
while (n) {
if (n & 1) ret = 1ll * ret * x % mod;
n >>= 1;
x = 1ll * x * x % mod;
}
return ret;
}
const int maxn = 1e6 + 7;
void next(int& x) { x = x * 10 + x % 10; }
void ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 11111;
vector<pair<int, int> > p;
vector<int> E[maxn];
int fa[maxn], d[maxn], N;
bool inQ[maxn];
int getfa(int x) {
if (x == fa[x]) return x;
return fa[x] = getfa(fa[x]);
}
bool isSame(int x, int y) { return getfa(x) == getfa(y); }
void merge(int x, int... | 4 |
#include <bits/stdc++.h>
using namespace std;
bool no;
int a[200030], n, k, w[200030], maxx, minn = 200030;
stack<int> s;
vector<int> v;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> k;
for (int i = 0; i < k; i++) {
cin >> a[i];
w[a[i]] = 1;
maxx = max(maxx, a[i]);
}... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long M = 998244353;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.precision(10);
cout << fixed;
int n, k;
cin >> n >> k;
vector<vector<vector<long long>>> dp(
k + 1, vector<vector<long long>>(n, vector<long long>(4)));
dp[1][0][... | 4 |
#include <bits/stdc++.h>
using namespace std;
char board[8][8];
vector<vector<int> > v(64);
void setUp() {
int k = 0;
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
vector<int> lol;
bool up = true;
bool down = true;
bool left = true;
bool right = true;
int pos = ... | 1 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
typedef pair<int,int> pi;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const double g = 9.8;
struct node {
int id;
double alpha, ansx, ansy;
} a[100010];
struct point {
double x, y;
} wall[100010];
int n, m;
double V;
bool cmpa(const node i, const node j) { return i.alpha < j.alpha; }
bool cmpid(const node i, const node j) { return i.id ... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long A[100008], sz, id, ROOT = 320;
int n, m, q;
vector<int> heavy;
int has[320][100008];
struct Set {
int type;
vector<int> el;
int inter[320];
long long val, cnt;
void read(int v) {
val = cnt = 0;
scanf("%lld", &sz);
type = (sz > ROOT);
if (... | 3 |
#include <bits/stdc++.h>
using namespace std;
int cal(int n) { return (n * (n - 1)) / 2; }
int n, col[105], row[105];
string s[105];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
cin >> s[i];
for (int j = 0; j < n; j++) {
if (s[i][j] == 'C') {
row[i]++;
col[j]++;
}
... | 1 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
int main() {
ll n, k;
cin >> n >> k;
vector<ll> a(n), f(n);
rep(i,n)
cin >> a[i];
rep(i,n)
cin >> f[i];
sort(a.begin(), a.end(), greater<ll>());
sort(f.begin(), f.end());
ll l... | 0 |
#include <queue>
#include <limits>
#include <vector>
#include <iostream>
using namespace std;
struct edge {
int to, cost;
edge(int to_, int cost_) : to(to_), cost(cost_) {};
};
bool operator<(const edge& e1, const edge& e2) {
return e1.cost < e2.cost;
}
template<class Type>
std::vector<Type> shortest_path(std::vecto... | 0 |
#include <iostream>
#include <algorithm>
using namespace std;
int x[100000], y[100000];
int main() {
int n, m;
cin >> n >> m;
for(int i=0; i<m; i++) cin >> x[i];
sort(x, x+m);
for(int i=0; i<m-1; i++) y[i] = x[i+1] - x[i];
sort(y, y+m-1);
int ans=0;
for(int i=0; i<m-n; i++) ans += ... | 0 |
#include <stdio.h>
int main() {
int N;
scanf("%d", &N);
int A[100000 + 1] = {0};
long long S = 0;
for (int i = 0; i < N; i++) {
int a;
scanf("%d", &a);
A[a]++;
S += a;
}
int Q;
scanf("%d", &Q);
for (int i = 0; i < Q; i++) {
int B, C;
scanf("%d%d", &B, &C);
printf("%lld\n", S += (C - B) * A[B])... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 500010;
bool f[MAXN];
int main() {
int n, d;
scanf("%d %d", &n, &d);
f[0] = 1;
for (int i = 0; i < n; i++) {
int x;
scanf("%d", &x);
for (int j = MAXN - 1 - x; j >= 0; --j) f[j + x] |= f[j];
}
int r = 1, sum = 0, ans = 0;
while (r ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr ... | 1 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int W, H, x1, x2, y1, y2, w, h;
cin >> W >> H >> x1 >> y1 >> x2 >> y2 >> w >> h;
int ans = INT_MAX;
if (x2 - x1 + w <= W) {
ans = min(ans, max(0, w - x1));
ans = min(ans, max(0, x2 - (W - w)));
}
if (y2 - y1 + h <= H) {
ans = min(ans, ... | 2 |
#include <bits/stdc++.h>
#define Int int64_t
using namespace std;
int main() {
int N, P;
cin >> N >> P;
string s;
cin >> s;
reverse(s.begin(), s.end());
if (P == 2 || P == 5) {
Int ans = 0;
for (int i = 0; i < N; ++i) {
if ((s[i] - '0') % P == 0) {
ans += N - i;
}
}
cout << ans << endl;
ret... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
struct qq {
int id, x, y, z, zb;
} a[200010];
bool cmp(qq a, qq b) {
return a.y ^ b.y
? a.y > b.y
: (a.z ^ b.z ? a.z > b.z : (a.x ^ b.x ? a.x < b.x : a.id < b.id));
}
bool cmp2(qq a, qq b) {
return a.z ^ b.z
? a.z > b.z... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, c1 = 0, c2 = 0;
bool b = 0, b1 = 0, b2 = 0;
string s;
cin >> s >> a;
string ss, ss1 = s;
reverse(ss1.begin(), ss1.end());
for (int i = 0; i < a; ++i) {
cin >> ss;
if (ss == s || ss == ss1) {
b = 1;
}
if (ss[1] == s[0])... | 1 |
#include <bits/stdc++.h>
using namespace std;
using namespace std;
bool sortinrev(const pair<long long int, long long int> &a,
const pair<long long int, long long int> &b) {
return (a.first > b.first);
}
long long int gcd(long long int a, long long int b) {
if (b == 0) return a;
return gcd(b, a % b... | 2 |
#include <bits/stdc++.h>
using namespace std;
void chmin(int64_t& a, int64_t b){
a = min(a, b);
}
int N;
int64_t A[5000];
vector<int> edges[5000];
int64_t dp[5000][5000][2], sub[5000][2];
int sz[5000];
const int64_t INF = 1e18;
void dfs(int i, int p){
for(int j=0; j<N; j++) for(int k=0; k<2; k++) dp[i][j][... | 0 |
#include <cstdio>
int N, M, n, m, a[501] = { -1000000000, 999999999 };
int main()
{
scanf("%d%d%d%d", &N, &M, &n, &m);
if (N % n)
{
puts("Yes");
for (int i = 1; i <= N; i++)
for (int j = 1; j <= M; j++)
printf("%d%c", a[i % n], " \n"[j == M]);
}
else if (M % m)
{
puts("Yes");
for (int i = 1; i <= N... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
;
long long n, x, y, a, b, c, t, q;
string s;
while (cin >> n) {
vector<pair<long long, long long> > v;
for (int i = (0); i < (n); i++) {
cin >> x >> y;
v.push_back(make_pair(x, y)... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int S = 3;
struct modint {
int n;
modint() : n(0) {}
modint(int n) : n(n) {}
};
using modints = array<modint, S>;
modints one = {1, 1, 1};
modint operator+(modint a, modint b) {
return modint((a.n += b.n) >= mod ? a.n - mod : a.n);
}
m... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--) {
int x, y, z;
cin >> x >> y >> z;
if (x != y && x != z && y != z)
cout << "NO\n";
else {
int mn = min({x, y, z}), mx = max({x, y, z});
int cnt = 0;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long mod = pow(10, 9) + 7;
int gcdExtended(int a, int b, int *x, int *y);
int modInverse(int b, int m) {
int x, y;
int g = gcdExtended(b, m, &x, &y);
if (g != 1) return -1;
return (x % m + m) % m;
}
int gcdExtended(int a, int b, int *x, int *y) {
if (a == 0) ... | 2 |
#include <bits/stdc++.h>
using namespace std;
char s[100005];
int sum[100005];
int in[100005];
int n, w, k;
int main() {
scanf("%d%d%d", &n, &k, &w);
scanf("%s", s + 1);
for (int i = 1; i <= n; i++) {
if (s[i] == '1')
sum[i] = sum[i - 1] + 1;
else
sum[i] = sum[i - 1];
}
for (int i = 1; i <... | 3 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T &x) {
int f = 0;
x = 0;
char ch = getchar();
for (; !isdigit(ch); ch = getchar()) f |= (ch == '-');
for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
if (f) x = -x;
}
const int mod = 1e9 + 7;
int power(int x, int p)... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 400000 + 77;
int n, k, A = N, a[N], LG[N];
map<int, int> M;
int main() {
for (int i = 2; i < N; ++i) LG[i] = LG[((i + 1) >> 1)] + 1;
scanf("%d %d", &n, &k);
for (int i = 1; i <= n; ++i) scanf("%d", a + i);
k *= 8;
sort(a + 1, a + 1 + n);
int ri = 1... | 1 |
#include <bits/stdc++.h>
using namespace std;
#define MAX_N 10000
typedef pair<long, long> P;
long N, d[MAX_N];
vector<P> edge[MAX_N];
void dijkstra(){
bool seen[N];
fill(seen, seen + N, false);
priority_queue<P, vector<P>, greater<P> > todo;
todo.push(P(0, 0));
while(!todo.empty()){
... | 0 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n, k, d;
cin >> n >> k >> d;
long long dis[n + 1], vis[n + 1];
for (long long i = 1; i <= n; i++) dis[i] = 1e18, vis[i] = 0;
queue<long long> bfs;
set<long long> b;
vector<pair<long long, long long> > e[n + 1];
for (long long i = 0; ... | 4 |
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace ... | 0 |
#include <bits/stdc++.h>
using namespace std;
inline void R(int &v) {
v = 0;
char c = 0;
int p = 1;
while (c < '0' || c > '9') {
if (c == '-') p = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
v = (v << 3) + (v << 1) + c - '0';
c = getchar();
}
v *= p;
}
inline int read() {
int x... | 3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.