Submission #1007566

# Submission time Handle Problem Language Result Execution time Memory
1007566 2024-06-25T07:55:38 Z PenguinsAreCute Counting Mushrooms (IOI20_mushrooms) C++17
0 / 100
1 ms 344 KB
#include "mushrooms.h"
#include <bits/stdc++.h>
using namespace std;
int arr1[6]={8,1,12,3,14,7};
int arr2[7]={69,4,20-7,6,9,4-2+0*9,11};
int det4(vector<int> f, vector<int> z, vector<int> o) {
  int guy = use_machine({f[0],f[1],f[2],f[3]});
  if(!guy) return (use_machine({f[0],z[0]})?15:0);
  if(guy==3) return (use_machine({f[0],z[0]})?10:5);
  if(guy==1) return arr1[use_machine({f[0],0,f[1],0,f[2],0})];
  return arr2[use_machine({f[0],0,f[1],0,1,f[2],1})];
}
int SQ = 140;
int count_mushrooms(int n) {
	if(n<=2*SQ) {
   	int ans = 1;
   		for(int i=1;i<n;i++) ans += !use_machine({0,i});
   		return ans;
 	}
 	vector<int> A={0}, B;
  for(int i=1;i<=2*SQ;) {
    if(A.size()<3||B.size()<2||i==2*SQ-1) {
      int erm = use_machine({i,0,i+1});
      if(!erm)
        A.push_back(i),
        A.push_back(i+1);
      else if(erm==2)
        B.push_back(i),
        B.push_back(i+1);
      else if(use_machine({0,i}))
        B.push_back(i),
        A.push_back(i+1);
      else
        A.push_back(i),
        B.push_back(i+1);
      i+=2;
    } else {
      int guy = det4({i,i+1,i+2,i+3},{A[0],A[1],A[2]},{B[0],B[1]});
      for(int j=0;j<4;j++) {
        if(guy&(1<<j)) B.push_back(i+j);
        else A.push_back(i+j);
      }
      i+=4;
    }
  }
 	int ans = A.size();
 	if(A.size()>B.size()) {
 		vector<int> v={A[0]};
 		for(int j=2*SQ+1;j<n;j++) {
 			v.push_back(j);
 			v.push_back(A[((j-1)%SQ)+1]);
 			if(j==n-1||(!(j%(2*SQ+1)))) {ans += (v.size()-1-use_machine(v))/2; v={A[0]};}
 		}
 	} else {
 		vector<int> v={B[0]};
 		for(int j=2*SQ+1;j<n;j++) {
 			v.push_back(j);
 			v.push_back(B[((j-1)%SQ)+1]);
 			if(j==n-1||!(j%(2*SQ+1))) {ans += use_machine(v)/2; v={B[0]};}
 		}
 	}
 	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Incorrect 0 ms 344 KB Duplicate value 0 in the query array.
7 Halted 0 ms 0 KB -