solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, n, k;
string s, f;
char ch;
cin >> t;
while (t--) {
cin >> n >> k;
map<char, int> m[k];
s = "";
for (int i = 0; i < n; i++) {
cin >> ch;
s += ch;
m[i % k][ch]++;
}
int ans = 0;
for (int i = 0; i < k... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
long long res = 1;
if (!(a % b)) res = 0;
while (a % b) {
if (a < b) swap(a, b);
a %= b;
if (a < b) swap(a, b);
res++;
}
return res + a / b;
}
int main() {
long long n, m;
cin >> n >> m;
long long res... | 1 |
#include <bits/stdc++.h>
using namespace std;
int a[1200], used[1200], pre[1201];
int dp[1200][1200][2], p[1200][1200][2];
vector<int> findMove(int l, int r, int c, int c2) {
if (pre[r + 1] - pre[l] == 0) return vector<int>();
if (c2 == -1) c2 = dp[l][r][1];
vector<int> v = findMove(l, p[l][p[l][r][c2] - 1][c2] -... | 6 |
#include<bits/stdc++.h>
using namespace std;
int main(){
while(1){
int n;
int t;
cin>>t;
if(!t) break;
cin>>n;
int a=0;
for(int i=0;i<n;++i){
int b,c;
cin>>b>>c;
a+=c-b;
}
if(a<t) cout<<t-a<<endl;
else cout<<"OK"<<endl;
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 30;
const long long linf = 1LL << 62;
const int MAX = 510000;
long long dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
long long dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const double pi = acos(-1);
const double eps = 1e-7;
template <typename T1, typename T2>
inline b... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MX = 1e6 + 5;
const int INF = 0x3f3f3f3f;
int n;
char S[MX];
int U[MX], D[MX];
long long Usum[MX], Dsum[MX];
long long checkU(int pos, int num) {
int l = 1, r = pos, m;
while (l <= r) {
m = (l + r) >> 1;
if (U[pos] - U[m - 1] >= num)
l = m + 1;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int mxn = 5005;
long long a[mxn], b[mxn], c[mxn], d[mxn], x[mxn], n, bg, ed;
bool use[mxn];
inline long long diff(long long i, long long j) {
if (x[i] < x[j])
return x[j] - x[i] + d[i] + a[j];
else
return x[i] - x[j] + c[i] + b[j];
}
int main() {
ios_bas... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
map<string, int> strmap;
pair<int, int> dp[maxn];
void solve(string &str, int loc, string last) {
if (dp[loc].first != -1 && dp[loc].second != -1) {
return;
}
if (last.length() == 2) {
dp[loc].first = 1;
} else {
dp[loc].second =... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int m,d;
cin>> m >> d;
int64_t cnt=0;
for(int i=1;i<=m;i++){
for(int j=22;j<=d;j++){
if(j-j/10*10<=1) continue;
else if(i==(j/10)*(j-j/10*10)) cnt++;
}
}
cout << cnt << endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m, a, b, ms[2222][2222], f[2222], A[2222], B[2222], ans[2222], k, u;
vector<int> v[2222];
void rec(int x, int o) {
if (f[x]) return;
f[x] = o;
for (int i = 0; i < v[x].size(); i++)
if (ms[x][v[x][i]]) rec(v[x][i], o);
}
int main() {
cin >> n >> m;
for (... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
bool ckmin(T& a, const T& b) {
return b < a ? a = b, 1 : 0;
}
template <class T>
bool ckmax(T& a, const T& b) {
return a < b ? a = b, 1 : 0;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MOD = 1000000007;
const char ... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long n, m;
bool valid(int x, int y) {
if (x >= 1 && x <= n && y >= 1 && y <= m)
return true;
else
return false;
}
int main() {
vector<pair<double, int> > vect;
double n, t1, t2, k, x, y;
cin >> n >> t1 >> t2 >> k;
for (int i = 1; i <= n; i++) {
... | 2 |
#ifdef _WIN32
#define getc_unlocked(stdin) getc(stdin)
#endif
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <string>
#include <list>
#include <bitset>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 300010, M = 10000005;
long long t, n, a[N], f[N], b[N], fs[N], bs[N], B, F;
int solve() {
scanf("%lld", &t);
while (t--) {
scanf("%lld", &n);
bool pos = 0;
B = 0, F = 0;
for (int i = 0; i < n; i++) {
scanf("%lld", &a[i]);
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int pow(int a, int b) {
long long k = 1;
for (int i = 0; i < b; ++i) k = k * a % 1000000007;
return k;
}
int a[150];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
string s;
cin >> n >> s;
for (int i = 0; i < n; ++i) ++a[s[i]];
int mx = 0;... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const long long int INF = 1e18;
const long double PI =
3.141592653589793238462643383279502884197169399375105820974944;
int main() {
int q;
cin >> q;
while (q--) {
int i, n, m, j;
cin >> n;
long long int a[n];
int o1 = 0,... | 1 |
#include <bits/stdc++.h>
using namespace std;
inline bool active (int etat, int i) {
return ((etat & (1 << i))!= 0);
}
inline bool est_ok (int nbDeja, int cote, int obj) {
if (nbDeja > obj)
return false;
int nbBlancsMin = (2-nbDeja);
int nbBlancsObj = cote-obj;
if (nbBlancsMin > nbBlancsObj)
return false;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
int a[200020], b[200020], vis[200020], fa[2][200020], ans, rk[200020],
ed[200020], Ans[200020];
int find(int f, int x) {
return x != fa[f][x] && ed[a[x]] ? fa[f][x] = find(f, fa[f][x]) : x;
}
inline void solve() {
scanf("%d%d", &n, &k);
for (int i = 1; i... | 6 |
#include <bits/stdc++.h>
const int maxn = 60, inf = 0x3f3f3f3f;
int head[maxn], cnt = 1, deg[maxn];
struct Edge {
int to, nxt, w;
} e[maxn << 1];
inline void addedge(int a, int b, int c) {
e[++cnt] = (Edge){b, head[a], c};
head[a] = cnt;
e[++cnt] = (Edge){a, head[b], c};
head[b] = cnt;
++deg[a], ++deg[b];
}... | 5 |
#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
#include <bits/stdc++.h>
int main() {
int n;
string s;
cin >> n >> s;
int64_t res = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < i; j++) {
if (s[i... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int z;
cin >> z;
while (z--) {
int k;
cin >> k;
int row, col;
if (k == 1) {
cout << 1 << " " << 1 << endl;
continue;
}
int j;
for (int i = 1; i * i < k; i++) {
j = i;
}
int a = j * j;
int b = j + 1... | 3 |
#include <bits/stdc++.h>
const long long mod = 1000 * 1000 * 1000 + 7;
const int maxn = 100009;
using namespace std;
int c, n, m, q, used[maxn], usedd[maxn][4], com[maxn], dd[maxn], g[maxn][4],
maxlen[maxn];
vector<int> v[maxn], arr[maxn], sum[maxn];
map<pair<int, int>, double> mp;
void comp(int w, int nom) {
use... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
const int len = 40;
int n;
long long a[N], l[N], r[N], res;
int tr[N * 41][2], cnt;
void add(long long x) {
int cur = 1;
for (int i = len; i >= 0; i--) {
int b = (x >> i) & 1;
if (tr[cur][b] == 0) tr[cur][b] = ++cnt;
cur = tr[cur][b];
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1;
const int M = 1e6 + 1;
const int mod = 1e9 + 7;
const int base = 41;
int n, sz[N];
string s[N];
vector<int> f[N], lcp[N];
long long g[M], h[M], t[M], w[M];
vector<long long> hashArr[N];
long long p[M];
long long getHash(int i, int l, int r) {
return... | 5 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int q, n, k;
cin >> q;
while (q--) {
cin >> n >> k;
string s;
cin >> s;
int ans = n, tmp = 0;
vector<int> dp(k, 0), cnt(k, 0);
for (int i = 0; i < n; i++) {
dp[i... | 5 |
#include <bits/stdc++.h>
using namespace std;
vector<int> rev;
int l[200002], r[200002], tim;
vector<int> g[200000];
void dfs(int u, int par) {
rev.push_back(u);
l[u] = tim;
tim++;
for (int i = 0; i < g[u].size(); i++) {
if (g[u][i] == par) continue;
dfs(g[u][i], u);
}
r[u] = tim - 1;
}
bool cmp(pai... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long fpm(long long b, long long e, long long m) {
long long t = 1;
for (; e; e >>= 1, b = b * b % m) e & 1 ? t = t * b % m : 0;
return t;
}
template <class T>
inline bool chkmin(T &a, T b) {
return a < b ? a = b, true : false;
}
template <class T>
inline bool c... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long rr[] = {0, 1, 1, 1, 0, -1, -1, -1};
long long cc[] = {1, 1, 0, -1, -1, -1, 0, 1};
const long long mod = 1e9 + 7;
const long long N = 300050;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
long long test = 1;
cin >> t... | 1 |
#include <bits/stdc++.h>
using namespace std;
string s[100000];
bool cmp(string a, string b) { return a + b < b + a; }
int main() {
int n;
while (cin >> n) {
for (int i = 0; i < n; ++i) cin >> s[i];
sort(s, s + n, cmp);
for (int i = 0; i < n; ++i) cout << s[i];
cout << endl;
}
return 0;
}
| 3 |
#include<iostream>
#include<cstdio>
int main(){
for(int i=1;i<10;i++){
for(int j=1;j<10;j++){
printf("%dx%d=%d\n",i,j,i*j);
}
}
return 0;
} | 0 |
#include<bits/stdc++.h>
using namespace std;
int A,B,C,D;
int main(){
cin>>A>>B>>C>>D;
if(A+B==C+D)cout<<"Balanced"<<endl;
else if(A+B>C+D)cout<<"Left"<<endl;
else cout<<"Right"<<endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 555250;
int a[N], c[N], h, vis[N];
vector<vector<int> > g;
map<int, int> ma;
void dfs(int u) {
if (vis[u]) return;
vis[u] = 1;
ma[c[u]]++;
for (int i = 0, to = g[u].size(); i < to; ++i) {
int v = g[u][i];
dfs(v);
}
}
int main() {
int n, m, ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int a[100000 + 10];
int p[100000 + 10];
int b[100000];
int po[100000 + 10];
int dp[100000 + 10];
int num;
void prime() {
memset(po, 0, sizeof(po));
memset(dp, 0, sizeof(dp));
memset(p, 0, sizeof(p));
int i = 0, sum = 0, x = 0;
p[0] = 1;
p[1] = 1;
for (i = 2; i... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
const int mod = 1e9 + 7;
long long int powmod(long long int a, long long int b) {
long long int res = 1;
a %= mod;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1) res = res * a % mod;
a = a * a % mod;
}
return res;
}
int nxt() {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const int Block = 400;
int l1, r1, l2, r2, n, m, cntB, Ans[N];
int F[N], s[N], v[N], A[N], B[N], q1[N], q2[N];
struct Query {
int l, r, id;
bool operator<(Query p) const {
return l / Block == p.l / Block ? r < p.r : l < p.l;
}
} Q[N];
inline ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1E-8;
const int dx4[4] = {1, 0, 0, -1};
const int dy4[4] = {0, -1, 1, 0};
const int inf = 0x3f3f3f3f;
const int N = 2E5 + 7;
struct Node {
int l, r;
int id;
} a[N];
int n;
int ans;
vector<int> ret;
bool cmp(Node x, Node y) {
if (x.l == y.l) return x... | 5 |
#include <bits/stdc++.h>
using namespace std;
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 << x; };
void __print(float x)... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int A, B;
char S[102];
bool possible;
inline int myabs(int x) { return (x < 0 ? -x : x); }
int main() {
cin >> A >> B >> S;
if (A == 0 && B == 0) {
cout << "Yes" << '\n';
return 0;
}
int gx = 0, gy = 0;
for (int i = 0; S[i] != 0... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string pal;
int num;
cin >> num;
cin.ignore();
cin >> pal;
int cant_total_t = 0;
for (int i = 0; i < pal.length(); i++) {
if (pal[i] == 'T') {
cant_total_t++;
}
}
int min_cant_h = 10000;
for (int i = 0; i < pal.length(); i++) {... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
int t;
cin >> t;
for (int j = 0; j < (t); ++j) {
int n;
int p;
cin >> n >> p;
int skok = 1;
int potrzebne = 2 * n + p;
while (true) {
for (int i = 0; i < n - skok && potrzebne > 0; i++) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
string s[2005];
map<string, int> m;
int main() {
ios::sync_with_stdio(0);
int n, k, ans = 0;
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> s[i];
m[s[i]]++;
}
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
string t;
... | 2 |
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stdio.h>
#include <cstring>
#include <queue>
#include <stack>
#include <functional>
#include <math.h>
#include <iomanip>
using namespace std;
#define Would
#define you
const int INF = 999999999;
const in... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long MAXX = 2e5 + 10, inf = 1e18 + 10;
long long T, n, a[MAXX], ans, mx;
int jump(int x) {
int l = x;
mx = -inf;
while (((a[x] < 0 && a[l] < 0) || (a[x] > 0 && a[l] > 0)) && l < n)
mx = max(a[l], mx), l++;
return l;
}
int main() {
ios::sync_with_std... | 3 |
#include <bits/stdc++.h>
using namespace std;
int T, p[4][2], ans = 0x3f3f3f3f;
const int perm[24][4] = {
{0, 1, 2, 3}, {0, 1, 3, 2}, {0, 2, 1, 3}, {0, 2, 3, 1}, {0, 3, 1, 2},
{0, 3, 2, 1}, {1, 0, 2, 3}, {1, 0, 3, 2}, {1, 2, 0, 3}, {1, 2, 3, 0},
{1, 3, 0, 2}, {1, 3, 2, 0}, {2, 0, 1, 3}, {2, 0, 3, 1}, {2, 1,... | 4 |
#include<iostream>
using namespace std;
int main(){
int dif,check=0;
int array[3][3];
for(int i=0;i<3;i++){
for(int j=0;j<3;j++)cin >>array[i][j];
if(i>=1){
dif=array[i][0]-array[0][0];
for(int k=0;k<3;k++){
if(dif!=array[i][k]-array[0][k])check=1;
}
}
}
if(check==1)cout<<"No"<<endl;
else cout... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long cnt[3005][3005];
vector<int> G[3005], G_inv[3005];
int main() {
ios::sync_with_stdio(false), cin.tie(nullptr);
int N, M;
cin >> N >> M;
for (int i = 0; i < M; i++) {
int a, b;
cin >> a >> b, a--, b--;
G[a].push_back(b);
G_inv[b].push_back(a... | 4 |
#include <bits/stdc++.h>
using namespace std;
int i, L;
char s[100005];
int main() {
scanf("%s", &s);
L = strlen(s);
for (i = 0; i < L; i++) printf("%c", s[i]);
for (i = L - 1; i >= 0; i--) printf("%c", s[i]);
}
| 1 |
#include<iostream>
#include<cstring>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
string g[12];
bool vis[12][12];
bool clr[12][12];
const int dy[] = {-1,0,1,0}, dx[] = {0,1,0,-1};
int dfs(int y,int x,int col){
if(g[y][x] != col)return 0;
if(vis[y][x])return 0;
vis[y][x] = true;
int res = 1;
r... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
int n;
vector<int> v;
cin >> n;
if (n == 1) {
cout << "+";
return 0;
}
for (int i(0), _n(n); i < _n; ++i) {
int t1;
cin >> t1;
v.push_back(t1);
}
int cur = 0;
reverse(v.begin(), v.end());
s... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a,b,c,d;
cin>>a>>b>>c>>d;
int x=-max(a,c)+min(b,d);
if (x>=0)
cout<<x;
else
cout<<0;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, k, t;
cin >> n >> k >> t;
if (t <= k) {
cout << t;
} else {
if (t <= n) {
cout << k;
} else if (t > n && t <= n + k) {
cout << k - (t % n);
} else {
cout << "0";
}
}
}
| 1 |
#include <iostream>
int w, h, dp[101][101][16];
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
// 00: down
// 01: right
// 11: 初期状態用
int rec(int x, int y, int r){
if(x <= h && y <= w);
else{
return 0;
}
if(dp[x][y][r] != -1){
return dp[x][y][r];
}
if... | 0 |
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
int main() {
int n, C;
int d[30][30], pre[3][30], c[505][505];
cin >> n >> C;
rep(i, C) rep(j, C) cin >> d[i][j];
rep(i, n) rep(j, n) cin >> c[i][j], c[i][j]--;
rep(col, C) rep(i, n) rep(j,... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n;
const int inf = 1e9, N = 25, M = 4e5 + 5, S = 4e6 + 5;
struct point {
int w, sum;
vector<int> t;
} a[N];
inline int read() {
int F = 1, ANS = 0;
char C = getchar();
while (C < '0' || C > '9') {
if (C == '-') F = -1;
C = getchar();
}
while (C >= ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string a, b, c, d;
long long n;
cin >> a >> b;
cin >> n;
cout << a << " " << b << "\n";
while (n) {
n--;
cin >> c >> d;
if (c != a) {
cout << a << " " << d << "\n";
b = d;
} else {
cout << d << " " << b << "\n";
... | 1 |
#include<cstdio>
#include<algorithm>
#define MN 210000
using namespace std;
int n,m,a,b;
long long c[MN],x[MN],mmh=1e18;
int main(){
scanf("%d%d",&n,&m);scanf("%d",&a);
for (int i=2;i<=n;i++){
scanf("%d",&b);
if (a<b){
c[1]+=b-a;
c[a+1]-=b-a;
c[b+1]+=b-a;
c[a+1]+=b+1;c[b+1]-=b+1;x[a+1]--;x[b+1]++... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3 * 1e5 + 10;
vector<int> IndSet, Match;
bool vis[maxn];
int main() {
int t;
scanf("%d", &t);
while (t--) {
memset(vis, 0, sizeof(vis));
IndSet.clear();
Match.clear();
int n, m;
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; i+... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string n,ans="No";cin>>n;
if(n[0]==n[1]&&n[1]==n[2])ans="Yes";
if(n[1]==n[2]&&n[2]==n[3])ans="Yes";
cout <<ans<<endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<char> line;
int len, jump, g, t;
cin >> len >> jump;
line.resize(len);
int i;
for (i = 0; i < len; ++i) {
cin >> line[i];
if (line[i] == 'G') g = i;
if (line[i] == 'T') t = i;
}
if (g > t) jump *= -1;
for (i = g; g > t ? i >... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
int n, m, k, nextInd, vRow[10007], vCol[10007], dis[50 * 10007];
map<pair<int, int>, int> vertex;
vector<pair<int, int> > g[50 * 10007];
bitset<50 * 10007> vis;
bitset<10007> lit[10007];
auto cmp = [](pair<int,... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int nmax = 20;
const int inf = 1e9 + 7;
const int modulo = 1e9 + 7;
const double linf = 1e36;
int main() {
long long n;
scanf("%I64d", &n);
long long ret = 3 * n * (n + 1) + 1;
printf("%I64d\n", ret);
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
double a[100];
int main() {
int n;
double b, sum, m = 0, one;
cin >> n >> b;
sum = b;
for (int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
m = max(m, a[i]);
}
one = sum / n;
if (m > one) {
cout << -1;
return 0;
}
for (int i = 0; i ... | 1 |
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
#define MAXN 100000
#define LL long long
int n,m;
vector<int> G[MAXN+5];
int du[MAXN+5],fa[MAXN+5];
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<n+m;i++)
{
int u,v;
scanf("%d%d",&u,&v);
G[... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, t, hc, hp;
cin >> n >> hp;
t = hp + 1;
n--;
while (n--) {
cin >> hc;
t += abs(hp - hc) + 2;
hp = hc;
}
cout << t;
}
| 2 |
// AOJ 0189 (http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0189)
#include<cstdio>
#include<algorithm>
#include<numeric>
#include<limits>
#define rep(i,a) for(int i=0;i<(a);++i)
typedef std::pair<int, int> P;
const int MAX_N = 10, INF = std::numeric_limits<int>::max()>>4;
int d[MAX_N][MAX_N];
int main()
{... | 0 |
#include <bits/stdc++.h>
using namespace std;
struct S {
long long s, a, b;
S(long long s, long long a, long long b) : s(s), a(a), b(b) {}
};
vector<S> v1, v2;
bool cmp1(S a, S b) { return abs(a.a - a.b) < abs(b.a - b.b); }
int main() {
long long N, S, i, s, a, b;
cin >> N >> S;
long long ans = 0;
long long... | 2 |
#include<bits/stdc++.h>
using namespace std;
const int INF = 1 << 28;
int main()
{
int N, T[50];
static int dp[2][2501][2501];
cin >> N;
for(int i = 0; i < N; i++) {
cin >> T[i];
}
fill_n(**dp, 2 * 2501 * 2501, INF);
dp[1][0][0] = 0;
for(int i = 0; i < N; i++) {
for(int j = 2500; j >= 0; j--... | 0 |
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using pii = pair<int, int>;
using vii = vector<pii>;
using ll = long long;
int solve();
int main(int argc, char* argv[]) {
::std::ios::sync_with_stdio(false);
::std::cin.tie(0);
::std::cout.tie(0);
int t = 1;
while (t--) {
solve();
}
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int a[100];
int main() {
int t;
cin >> t;
while (t--) {
memset(a, 0, sizeof(a));
string s, s1;
cin >> s >> s1;
sort(s.begin(), s.end());
for (int i = 0; i < s.length(); i++) {
a[s[i] - 'a']++;
}
if (!(s1 == "abc" && a[0] && a[1] && a[... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int q;
cin >> q;
while (q--) {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
int m = 0;
for (int i = n - 1; i >= 0; i--) {
int k = min(a[i], n - i);
m = max(m, k);
}
cou... | 1 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
string s;
cin >> s;
long long int ob = -1, cb = -1;
long long int i, n = s.length();
for (i = 0; i < n; i++) {
if (s[i] == '[') {
ob = i;
break;
}
}
for (i = n - 1; i >= 0; i--) {
if (s[i] == ']') {
cb = i;
br... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long dp[110][110][110], pi[110];
vector<long long> trace[110][110][110];
bool valid[110][110][110];
string virus;
void kmpPreprocess() {
long long i = 0, j = -1;
pi[0] = -1;
while (i < virus.size()) {
while (j >= 0 && virus[i] != virus[j]) {
j = pi[j];
... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long int mod = 1000000007;
long long int powmod(long long int a, long long int b) {
long long int res = 1;
a %= mod;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1) res = res * a % mod;
a = a * a % mod;
}
return res;
}
long long int gcd(long long in... | 2 |
#include <bits/stdc++.h>
using namespace std;
char getc() {
char c = getchar();
while ((c < 'A' || c > 'Z') && (c < 'a' || c > 'z') && (c < '0' || c > '9'))
c = getchar();
return c;
}
int gcd(int n, int m) { return m == 0 ? n : gcd(m, n % m); }
int read() {
int x = 0, f = 1;
char c = getchar();
while (c... | 2 |
#include <cstdio>
#include <cmath>
#include <complex>
using namespace std;
typedef complex<double> P;
void koch(int n, P p1, P p2)
{
if (n == 0)
return;
P s = p1 + (p2 - p1) / 3.0;
P t = p1 + (p2 - p1) / 3.0 * 2.0;
P u = s + (t - s) * polar(1.0, M_PI * 1 / 3);
koch(n - 1, p1, s);
prin... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5+20;
int n,a[N],c[N],d[N];
long long s1[N],s2[N],f[N];
int main(void)
{
scanf("%d",&n);
for (int i=1;i<=n;i++)
scanf("%d",&a[i]) , c[a[i]]++;
for (int i=1;i<=n;i++) d[c[i]]++;
for (int i=1;i<=n;i++)
s1[i] = s1[i-1] + 1LL * i ... | 0 |
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int main(){
int n,m;
long long a[60],b[60],c[60],d[60];
cin >> n >> m;
for(int i=0; i<n; i++){
cin >> a[i] >> b[i];
}
for(int i=0; i<m; i++){
cin >> c[i] >> d[i];
}
for(int i=0; i<n; i++){
int minnum=1e9,mini=51;
for(int k=0; k... | 0 |
#include<iostream>
using namespace std;
int cntDivisor( int a )
{
int cnt = 0;
for( int i = 1; i <= a; i++ )
if( a % i == 0 )
cnt++;
return cnt;
}
int main()
{
int n;
cin >> n;
for( int i = n; i <= 1024; i++ )
{
if( n == cntDivisor( i ) )
{
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
string p[n], s, ans;
for (int i = 0; i < n; i++) cin >> p[i];
cin >> s;
ans = s;
char ch;
cin >> ch;
if (ch < 'a') ch += char(32);
for (int i = 0; i < s.length(); i++) {
for (int j = 0; j < n; j++) {
if (i + ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int n = 100002;
long long Vs[n], days[n], tooMuch[n];
int N;
int main() {
cin >> N;
for (int i = 0; i < N; ++i) cin >> Vs[i];
long long Tsum = 0;
for (int i = 0; i < N; ++i) {
cin >> days[i];
Vs[i] += Tsum;
tooMuch[i] = days[i] * (N - i - 1);
T... | 2 |
#include <bits/stdc++.h>
int larger(int m, int n) {
if (m > n)
return m;
else
return n;
}
int main() {
int a, b, c, c1, c2, c3, c4, c5, s1, s2, s3, s4;
scanf("%d%d%d", &a, &b, &c);
c1 = a + (b * c);
c2 = a * (b + c);
c3 = a * b * c;
c4 = (a + b) * c;
c5 = a + b + c;
s1 = larger(c1, c2);
s2... | 1 |
#include <bits/stdc++.h>
long long num[1000000], sum[4][1000000], f[4][1000000];
char str[1000000];
long long prime[1000], ex[1000];
long long NN;
void bf(long long id, long long pre) {
long long a, b, i;
if (id > *prime) {
if (pre > 0) {
b = NN / pre;
a = ((b - 1) * b) >> 1;
a = a * pre + b;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
template <typename F, typename S>
ostream &operator<<(ostream &os, const pair<F, S> &p) {
return os << "(" << p.first << ", " << p.second << ")";
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
os << "{";
typename vector<T>::const_iterat... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main()
{
int w, h;
while(cin >> w >> h, w || h){
int s[33][33], c[4];
for(int i = 0; i < h; i++){
for(int j = 0; j < w; j++) cin >> s[i][j];
}
for(int i = 0; i < 4; i++) cin >> c[i];
const int inf = (1 << 25);
int a[4][33][33];
in... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int a[n];
bool pos = true;
for (int &i : a) cin >> i;
sort(a, a + n);
for (int i = 0; i < n - 1; i++) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
long long a[n + 1], i;
for (i = 1; i <= n; i++) cin >> a[i];
long long k = -1, ans = 0, cf = 0;
map<long long, long long> m;
m[0] = 0;
for (i = 1; i <= n; i++) {
cf += a[i];
if (m.find(cf) != m.end()) k = max(k, m[... | 3 |
#include <bits/stdc++.h>
using namespace std;
char grid[350][350];
int n, m, tot, k;
bool isvalid(int i, int j) { return (i >= 0 && j >= 0 && i < n && j < m); }
vector<pair<int, int> > star[350];
int main() {
scanf("%d", &n), scanf("%d", &m), scanf("%d", &k);
for (int i = 0; i < n; ++i) scanf(" %s", &grid[i]);
fo... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, q, fa[N];
double a[N];
struct Tree {
int l, r, lz;
double val, mul, add;
} tr[N * 4];
void build(int l, int r, int t) {
tr[t].l = l;
tr[t].r = r;
tr[t].lz = tr[t].val = tr[t].add = 0;
tr[t].mul = 1;
if (l == r) {
fa[l] = t;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
clock_t tstart = clock();
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, k;
cin >> n >> k;
int ans = 0;
for (int i = 0; i < n; i++) {
int num;
cin >> num;
ans += num / k;
if (num % k) ans++;
}
cout << (ans ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 100005;
long long p26[MAX], p25[MAX], inv[MAX];
long long f[MAX], mod = 1e9 + 7;
int ans[500][MAX];
map<int, int> mp;
long long ny(long long x) {
int m = mod - 2;
long long rt = 1, now = x;
while (m) {
if (m & 1) rt = (rt * now) % mod;
now = (n... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, p = 1;
bool OK = false;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (i % 2 != 0)
cout << "#";
else {
if (p % 2 != 0) {
if (j != m)
cout << ".";
... | 1 |
#include <cstdio>
#include <cctype>
int main()
{
char s[1200];
scanf("%[^\n]", s);
for(int i = 0;s[i] != '\0'; i++){
if(isupper(s[i])) s[i] = tolower(s[i]);
else s[i] = toupper(s[i]);
}
printf("%s\n", s);
return 0;
} | 0 |
#include<iostream>
using namespace std;
int main(){
int n;cin>>n;
if(n<105)cout<<0<<endl;
else if(n<135)cout<<1<<endl;
else if(n<165)cout<<2<<endl;
else if(n<189)cout<<3<<endl;
else if(n<195)cout<<4<<endl;
else cout<<5<<endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_FL_N = 110;
const int FL_INF = 1e9;
struct edge;
vector<edge> ve[MAX_FL_N];
struct edge {
int v, fl, r;
edge(int _v = 0, int _fl = 0, int _r = 0) : v(_v), fl(_fl), r(_r) {}
void add(int a) {
fl += a;
ve[v][r].fl -= a;
}
int cap() { return ve[... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x7fffffff;
const int MOD = 1000003;
template <typename tn>
inline tn read() {
char ch;
tn f = 1;
while (!isdigit(ch = getchar()))
if (ch == '-') f = -1;
tn x = ch - '0';
while (isdigit(ch = getchar())) x = x * 10 + ch - '0';
return x * f;
}
... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long int power(long long int x, long long int y) {
long long int res = 1;
while (y > 0) {
if (y & 1) res = res * x;
y = y >> 1;
x = x * x;
}
return res;
}
int main() {
long long int n, m;
cin >> n >> m;
set<long long int> rw, cm;
for (long l... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
int p[N * N];
int f(int u) { return u == p[u] ? u : p[u] = f(p[u]); }
bool join(int a, int b) {
a = f(a), b = f(b);
if (a == b) return false;
p[a] = b;
return true;
}
int n, m;
char mat[N][N];
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
b... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
map<string, int> q;
int n, m, cnt = 0;
cin >> n >> m;
int ans1 = n, ans2 = m;
while (n--) {
cin >> s;
q[s]++;
}
while (m--) {
cin >> s;
q[s]++;
if (q[s] > 1) cnt++;
}
if (cnt % 2 == 1) ans2 -= 1;
if (ans1 <= a... | 2 |
#include <bits/stdc++.h>
const int LG = 21;
const int N = 400005;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const long long INFLL = 1e18;
using namespace std;
void solve(long long n) {
for (long long st = max(1LL, n / 3 - 3); st <= min(n, n / 3 + 3); st++) {
long long okay = 1;
for (long long ... | 1 |
#include <bits/stdc++.h>
using namespace std;
bool isOdd(int num) { return !(num % 2 == 0); }
int main() {
int n, allX = 0, allY = 0, oddDiff = 0;
cin >> n;
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
allX += x;
allY += y;
int z = x - y;
if (isOdd(z)) oddDiff = z;
}
if (isOd... | 1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.