제출 #484977

#제출 시각아이디문제언어결과실행 시간메모리
484977M4mou버섯 세기 (IOI20_mushrooms)C++17
91.13 / 100
9 ms320 KiB
#include <bits/stdc++.h> #include "mushrooms.h" #pragma GCC optimize ("Ofast") #pragma GCC target ("avx2") using namespace std; using ll = long long; using vi = vector<int>; #define pb push_back #define ff first #define ss second #define lb lower_bound #define all(x) (x).begin() , (x).end() string s;/* int use_machine(vector<int> a){ int c = 0; for(int i = 1;i<a.size();i++){ if(s[a[i]] != s[a[i-1]])c++; } return c; }*/ int count_mushrooms(int n) { int cnt = 1; if(n < 226){ for(int i = 1;i<n;i++){ vector<int> a; a.push_back(0); a.push_back(i); int x = use_machine(a); if(x == 0)cnt++; } return cnt; } int k = 220; vector<int>arrA, arrB; arrA.pb(0); for(int i = 1;i<3;i++){ vector<int> a; a.push_back(0); a.push_back(i); int x = use_machine(a); if(x == 0){ arrA.pb(i); cnt++; } else arrB.pb(i); } for(int i = 3;i<k;i+=2){ vector<int> a; if(arrA.size() > arrB.size()){ a = {0,i,arrA[1],i+1}; int x = use_machine(a); if(x == 0){ arrA.pb(i); arrA.pb(i+1); }else if(x == 1){ arrA.pb(i); arrB.pb(i+1); }else if(x == 2){ arrB.pb(i); arrA.pb(i+1); }else { arrB.pb(i); arrB.pb(i+1); } } else { a = {arrB[0],i,arrB[1],i+1}; int x = use_machine(a); if(x == 0){ arrB.pb(i); arrB.pb(i+1); } else if( x== 1){ arrB.pb(i); arrA.pb(i+1); } else if(x == 2){ arrA.pb(i); arrB.pb(i+1); } else { arrA.pb(i); arrA.pb(i+1); } } } cnt = arrA.size(); #define sz(x) (int)x.size() { int i = k+1; while(i<n){ if(sz(arrA) >= sz(arrB)){ vector<int> a; for(int j : arrA){ a.pb(j); a.pb(i); i++; if(i == n)break; } int x = use_machine(a); cnt += (int)(a.size()/2) - (x+1)/2; if(x%2){ arrB.pb(a.back()); } else arrA.pb(a.back()); } else { vector<int> b; for(int j : arrB){ b.pb(j); b.pb(i); i++; if(i == n)break; } int x = use_machine(b); cnt += (x+1)/2; if(x%2){ arrA.pb(b.back()); } else arrB.pb(b.back()); } } } return cnt; }/* int main(){ while(1){ cin >> s; cout << count_mushrooms(s.size()) << endl; } }*/
#Verdict Execution timeMemoryGrader output
Fetching results...