제출 #312850

#제출 시각아이디문제언어결과실행 시간메모리
312850DanerZeinCounting Mushrooms (IOI20_mushrooms)C++14
0 / 100
1 ms384 KiB
#include "mushrooms.h" #include <bits/stdc++.h> using namespace std; typedef vector<int> vi; int punt[4]; int count_mushrooms(int n) { int res=1; int ca,cb; vi pa,pb; pa.push_back(0); ca=cb=0; for(int i=1;i<=min(2,n-1);i++){ vector<int> aux; aux.push_back(0); aux.push_back(i); //cout<<use_machine(aux)<<" "<<i<<endl; if(use_machine(aux)){ cb++; pb.push_back(i); } else{ ca++; res++; pa.push_back(i); } } ca++; memset(punt,0,sizeof punt); bool sw=0; if(ca>=cb){ int p=3; punt[0]=3; int j=1; while(true){ p--; punt[j]=punt[j+1]=p; j+=2; if(p==0) break; } sw=1; } else{ int p=0; punt[0]=0; int j=1; while(true){ p++; punt[j]=punt[j+1]=p; j+=2; if(p==3) break; } } int c=max(ca,cb); //cout<<ca<<" "<<cb<<endl; for(int i=3;i<n;i+=c){ //cout<<i<<endl; vector<int> aux; for(int j=0;j<c;j++){ if(i+j<n) aux.push_back(i+j); if(sw==1) aux.push_back(pb[j]); else aux.push_back(pa[j]); } res+=(punt[use_machine(aux)]); } return res; }

컴파일 시 표준 에러 (stderr) 메시지

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:48:24: warning: iteration 1 invokes undefined behavior [-Waggressive-loop-optimizations]
   48 |       punt[j]=punt[j+1]=p;
      |               ~~~~~~~~~^~
mushrooms.cpp:50:7: note: within this loop
   50 |       if(p==3) break;
      |       ^~
mushrooms.cpp:36:24: warning: iteration 1 invokes undefined behavior [-Waggressive-loop-optimizations]
   36 |       punt[j]=punt[j+1]=p;
      |               ~~~~~~~~~^~
mushrooms.cpp:38:7: note: within this loop
   38 |       if(p==0) break;
      |       ^~
mushrooms.cpp:48:23: warning: array subscript 4 is above array bounds of 'int [4]' [-Warray-bounds]
   48 |       punt[j]=punt[j+1]=p;
      |               ~~~~~~~~^
mushrooms.cpp:5:5: note: while referencing 'punt'
    5 | int punt[4];
      |     ^~~~
mushrooms.cpp:48:23: warning: array subscript 6 is above array bounds of 'int [4]' [-Warray-bounds]
   48 |       punt[j]=punt[j+1]=p;
      |               ~~~~~~~~^
mushrooms.cpp:5:5: note: while referencing 'punt'
    5 | int punt[4];
      |     ^~~~
mushrooms.cpp:48:13: warning: array subscript 5 is above array bounds of 'int [4]' [-Warray-bounds]
   48 |       punt[j]=punt[j+1]=p;
      |       ~~~~~~^
mushrooms.cpp:5:5: note: while referencing 'punt'
    5 | int punt[4];
      |     ^~~~
mushrooms.cpp:36:23: warning: array subscript 4 is above array bounds of 'int [4]' [-Warray-bounds]
   36 |       punt[j]=punt[j+1]=p;
      |               ~~~~~~~~^
mushrooms.cpp:5:5: note: while referencing 'punt'
    5 | int punt[4];
      |     ^~~~
mushrooms.cpp:36:23: warning: array subscript 6 is above array bounds of 'int [4]' [-Warray-bounds]
   36 |       punt[j]=punt[j+1]=p;
      |               ~~~~~~~~^
mushrooms.cpp:5:5: note: while referencing 'punt'
    5 | int punt[4];
      |     ^~~~
mushrooms.cpp:36:13: warning: array subscript 5 is above array bounds of 'int [4]' [-Warray-bounds]
   36 |       punt[j]=punt[j+1]=p;
      |       ~~~~~~^
mushrooms.cpp:5:5: note: while referencing 'punt'
    5 | int punt[4];
      |     ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...