Submission #724896

#TimeUsernameProblemLanguageResultExecution timeMemory
724896MohamedAliSaidaneCounting Mushrooms (IOI20_mushrooms)C++14
0 / 100
8 ms208 KiB
#include<bits/stdc++.h> #include "mushrooms.h" #include<ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; typedef vector<int> vi; typedef vector<ll> vll; typedef pair<int,int> pii; typedef vector<pii> vpi; #define ff first #define ss second #define pb push_back #define all(x) (x).begin(),(x).end() const ll MOD = 1e9 + 7, INF = 1e18; ll mod(ll x, ll m = MOD) {return (x + m) % m;} int N; string S; /* int use_machine(vi v) { int rep = 0; for(int i = 0; i < (int)(v.size()) - 1; i++) rep += (S[v[i]] != S[v[i + 1]]); return rep; } */ int count_mushrooms(int n) { char c = 'A', d= 'B'; int a = 0, b = 1; int u = use_machine({0, 1}); if(n == 2) return 2 - u; if(u == 1) { if(use_machine({0, 2})) { a= 2; swap(c, d); } else b = 2; } vi A = {a, b}; vi B; for(int j = 0; j < 3; j++) if(j != a && j != b) B.pb(j); int sza = 2, szb = 1; int last = 2; for(int i = 3; max(sza, szb) * max(sza, szb) < n; i+= 2) { if(i == n -1) { last = i; if(use_machine({a, i})) B.pb(i); else A.pb(i); } else { last = i + 1; u = use_machine({a, i, b, i + 1}); if(u == 1) { A.pb(i); B.pb(i + 1); } else if(u == 0) { A.pb(i); A.pb(i + 1); } else if(u == 2) { A.pb(i + 1); B.pb(i); } else { B.pb(i); B.pb(i + 1); } } sza = (int)(A.size()); szb = (int)(B.size()); } if(sza < szb) { swap(c, d); swap(A, B); swap(sza, szb); } int cnt = sza; for(int j = last + 1; j < n; j += sza) { vi v; for(int k = 0; k < min(n - j, sza); k++) { v.pb(A[k]); v.pb(j + k); } cnt += min(n - j, sza) - (use_machine(v) + 1)/2; } if(c == 'A') return cnt; else return n - cnt; } /* int32_t main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> N; cin >> S; cout << count_mushrooms(N); } */
#Verdict Execution timeMemoryGrader output
Fetching results...