Codeforces対策(随時更新)
■マス
十字架があるかないか→https://babcs2035.hateblo.jp/entry/2019/06/12/063912
■数列
maximum possible number of elements divisible by 3 (1位の人)⇒
int main(){ cin>>n>>k; REP(i,n)cin>>h[i]; sort(h,h+n); ll ans = 1ll<<60; REP(i,n)if(i+k<=n)CHMIN(ans,h[i+k-1]-h[i]); cout<<ans<<endl; return 0; }
全項の積の最大値(2位の人)
int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; int a[n]; for(int i = 0; i < n; ++i) { cin >> a[i]; if(a[i] >= 0) a[i] = -a[i] - 1; } if(n % 2 == 1) { int mn = -1, mxi; for(int i = 0; i < n; ++i) if(mn > a[i]) { mn = a[i]; mxi = i; } if(mn == -1) a[0] = 0; else a[mxi] = -a[mxi] - 1; } for(int i = 0; i < n; ++i) cout << a[i] << " "; }
■構文解析(1位の人)
#include <iostream> #include <vector> using namespace std; using ll = long long; const ll MAXV = (1ll<<32); int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; ll res = 0; vector<ll> stack = {1}; for (int i = 0; i < n; ++i) { string str; cin >> str; if (str == "add") { res += stack.back(); } else if (str == "for") { ll k; cin >> k; stack.push_back(min(MAXV, k*stack.back())); } else if (str == "end") { stack.pop_back(); } } if (res >= MAXV) cout << "OVERFLOW!!!\n"; else cout << res << '\n'; }
■文字列(2位の人)
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin>>n; stringstream ss; for (int _ = 0; _ < n; _++) { string a,b; cin>>a>>b; int i = 0, j = 0; bool success = 1; while (i<a.length() && j<b.length()) { int ii = i; while (ii<a.length() && a[ii]==a[i]) ii++; int jj = j; while (jj<b.length() && b[jj]==b[j]) jj++; if (a[i] != b[j]) success = 0; else if (ii-i>jj-j) success = 0; i = ii; j = jj; } if (i!=a.length() || j!=b.length()) success = 0; ss << (success?"YES":"NO") << endl; } cout << ss.str(); return 0; }