Submission #310115

#TimeUsernameProblemLanguageResultExecution timeMemory
310115peti1234Counting Mushrooms (IOI20_mushrooms)C++17
0 / 100
2 ms384 KiB
#include <bits/stdc++.h> #include "mushrooms.h" using namespace std; vector<int> a, b, sz, s; int sa, sb, pos, ert, x, adb; bool v[20002]; void pb(int x) { sz.push_back(x); } void ap(int x) { a.push_back(x); } void bp(int x) { b.push_back(x); } void cl() { sz.clear(); } /* int use_machine(vector<int>x) { int ans=0; for (int i=1; i<x.size(); i++) ans+=(v[x[i]]!=v[x[i-1]]); sort(x.begin(), x.end()); for (int i=1; i<x.size(); i++) { if (x[i]==x[i-1]) cout << "ismetlodes " << "\n"; } return ans; } */ void add(int a) { if (x%2) bp(a); else ap(a); } void fadd(int a) { if (x%2) ap(a); else bp(a); } int kerd() { s=sz; sort(s.begin(), s.end()); for (int i=1; i<s.size(); i++) { //if (s[i]==s[i-1]) cout << "bazdmeg " << s.size() << endl; } return use_machine(sz); } void ek(int a) { pb(0), pb(a); x=kerd(); add(a), cl(); } int count_mushrooms(int n) { ap(0), ert=sqrt(n); ert=110; if (n<220) { for (int i=1; i<n; i++) ek(i); return a.size(); } for (int i=1; i<=2; i++) ek(i); if (sa>2) { pb(a[0]), pb(3), pb(a[1]), pb(4); x=kerd(); add(4), x/=2; add(3); } else { pb(b[0]), pb(3), pb(b[1]), pb(4); x=kerd(); fadd(4), x/=2; fadd(3); } pos=5; sa=a.size(), sb=b.size(); while(max(sa, sb)<ert) { cl(); if (sa>2) { pb(a[0]), pb(pos), pb(a[1]), pb(pos+1), pb(a[2]), pb(pos+2); x=kerd(); add(pos+2); if (x<2) ap(pos), ap(pos+1), pos+=3; else if (x>=4) bp(pos), bp(pos+1), pos+=3; else { if (sb>1) { cl(); pb(b[0]), pb(pos), pb(b[1]), pb(a[0]), pb(pos+1), pb(a[1]), pb(pos+3), pb(a[2]), pb(pos+4); x=kerd()-1; add(pos+4); x/=2; add(pos+3); x/=2; add(pos+1), fadd(pos); pos+=5; } else { cl(); pb(a[0]), pb(pos), pb(a[1]), pb(pos+3); x=kerd(); add(pos+3), x/=2; add(pos), fadd(pos+1); pos+=4; } } } else { pb(b[0]), pb(pos), pb(b[1]), pb(pos+1), pb(b[2]), pb(pos+2); x=kerd(); fadd(pos+2); if (x<2) bp(pos), bp(pos+1), pos+=3; else if (x>=4) ap(pos), ap(pos+1), pos+=3; else { if (sa>1) { cl(); pb(a[0]), pb(pos), pb(a[1]), pb(b[0]), pb(pos+1), pb(b[1]), pb(pos+3), pb(b[2]), pb(pos+4); x=kerd()-1; fadd(pos+4); x/=2; fadd(pos+3); x/=2; fadd(pos+1), add(pos); pos+=5; } else { cl(); pb(b[0]), pb(pos), pb(b[1]), pb(pos+3); x=kerd(); fadd(pos+3), x/=2; fadd(pos), add(pos+1); pos+=4; } } } sa=a.size(), sb=b.size(); } while(pos<n) { cl(); if (sa>=sb) { for (int i=0; i<sa && pos+i<n; i++) { pb(a[i]), pb(pos+i); } x=kerd(); int y=sz.back(); add(y); pos=1+y; int si=sz.size(); adb+=((si-2)/2-x/2); } else { for (int i=0; i<sb && pos+i<n; i++) { pb(b[i]), pb(pos+i); } x=kerd(); int y=sz.back(); fadd(y); pos=1+y; adb+=(x/2); } sa=a.size(), sb=b.size(); } return sa+adb; } /* int main() { int p, db; cin >> p; for (int i=1; i<p; i++) cin >> v[i]; cout << count_mushrooms(p); return 0; } */

Compilation message (stderr)

mushrooms.cpp: In function 'int kerd()':
mushrooms.cpp:41:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |     for (int i=1; i<s.size(); i++) {
      |                   ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...