{{ message }}

Instantly share code, notes, and snippets.

# juanplopes/A.cpp

Created Nov 7, 2019
Codeforces Round #595 (Div. 3)
 #include #include using namespace std; int T; int main() { ios_base::sync_with_stdio(false); int test; cin >> test; int N; while(cin >> N) { bool odd = false, even = false; for(int i=0; i> T[i]; if (T[i]%2 == 0) even = true; else odd = true; } sort(T, T+N); int mindif = 10000; for(int i=1; i 1 ? 1 : (even+odd)) << endl; } }
 #include #include #include using namespace std; int P; int V; int main() { ios_base::sync_with_stdio(false); int test; cin >> test; int N; while(cin >> N) { for(int i=1; i<=N; i++) cin >> P[i]; memset(V, 0, sizeof V); for(int i=1; i<=N; i++) { if (V[i] > 0) continue; int count = 1; int x = P[i]; while(x != i) { count++; x = P[x]; } V[i] = count; x = P[i]; while(x != i) { V[x] = count; x = P[x]; } } for(int i=1; i<=N; i++) { if (i>1) cout << " "; cout << V[i]; } cout << endl; } }
 #include #include #include using namespace std; long long T; int main() { ios_base::sync_with_stdio(false); long long test; cin >> test; long long N; while(cin >> N) { int count = 0; while(N > 0) { T[count++] = N%3; N/=3; } long long carry = 0; long long lastChange = -1; for(int i=0; i=0; i--) { answer *= 3; answer += i
 #include #include #include #include #include #define MAX using namespace std; struct Seg { int index, a, b; Seg(int index, int a, int b) : index(index), a(a), b(b) {} inline bool operator<(const Seg& that) const{ if (b!=that.b) return b>that.b; return index A; vector B; set S; int X; int main() { ios_base::sync_with_stdio(false); int N, K; while(cin >> N >> K) { memset(A, 0, sizeof A); memset(B, 0, sizeof B); int minn = 100000000; int maxx = 0; for(int i=0; i> a >> b; minn = min(minn, a); maxx = max(maxx, b); A[a].push_back(Seg(i, a, b)); B[b].push_back(Seg(i, a, b)); } int answer = 0; for(int i=minn; i<=maxx; i++) { for(int j=0; j K) { X[answer++] = S.begin()->index; S.erase(S.begin()); } for(int j=0; j0) cout << " "; cout << X[i]+1; } cout << endl; } }
 #include #include #include using namespace std; long long A, B; long long T1, T2, TX; int main() { ios_base::sync_with_stdio(false); long long N, C; while(cin >> N >> C) { for(int i=0; i> A[i]; for(int i=0; i> B[i]; T1 = 0; T2 = 20000000000ll; for(int i=1; i0) cout << " "; cout << min(T1[i], T2[i]); } cout << endl; } }