제출 #730655

#제출 시각아이디문제언어결과실행 시간메모리
730655lucriMiners (IOI07_miners)C++17
92 / 100
330 ms102040 KiB
#include <iostream> using namespace std; int n,pd[100010][260],ans; char a[100010]; int codifica(char a) { if(a=='M') return 1; if(a=='B') return 2; return 3; } void adauga(int poz,int a,int b,int c,int d,int ad) { int valcal; if(a&&b==0||c&&d==0) return; if(a&&b) { valcal=pd[poz-1][a*4*4*4+b*4*4+c*4+d]+3; if(a==b||a==ad) --valcal; if(b==ad) --valcal; if(valcal>pd[poz][b*4*4*4+ad*4*4+c*4+d]) pd[poz][b*4*4*4+ad*4*4+c*4+d]=valcal; } else if(b) { valcal=pd[poz-1][a*4*4*4+b*4*4+c*4+d]+2; if(b==ad) --valcal; if(valcal>pd[poz][b*4*4*4+ad*4*4+c*4+d]) pd[poz][b*4*4*4+ad*4*4+c*4+d]=valcal; } else if(pd[poz-1][a*4*4*4+b*4*4+c*4+d]+1>pd[poz][b*4*4*4+ad*4*4+c*4+d]) pd[poz][b*4*4*4+ad*4*4+c*4+d]=pd[poz-1][a*4*4*4+b*4*4+c*4+d]+1; if(c&&d) { valcal=pd[poz-1][a*4*4*4+b*4*4+c*4+d]+3; if(c==d||c==ad) --valcal; if(d==ad) --valcal; if(valcal>pd[poz][a*4*4*4+b*4*4+d*4+ad]) pd[poz][a*4*4*4+b*4*4+d*4+ad]=valcal; } else if(d) { valcal=pd[poz-1][a*4*4*4+b*4*4+c*4+d]+2; if(d==ad) --valcal; if(valcal>pd[poz][b*4*4*4+ad*4*4+c*4+d]) pd[poz][a*4*4*4+b*4*4+d*4+ad]=valcal; } else if(pd[poz-1][a*4*4*4+b*4*4+c*4+d]+1>pd[poz][a*4*4*4+b*4*4+d*4+ad]) pd[poz][a*4*4*4+b*4*4+d*4+ad]=pd[poz-1][a*4*4*4+b*4*4+c*4+d]+1; } int main() { cin>>n>>a+1; for(int i=0;i<=255;++i) pd[0][i]=-2000000000; pd[0][0]=0; for(int i=1;i<=n;++i) { for(int j=0;j<=255;++j) pd[i][j]=-2000000000; int cod=codifica(a[i]); for(int a=0;a<=3;++a) for(int b=0;b<=3;++b) for(int c=0;c<=3;++c) for(int d=0;d<=3;++d) adauga(i,a,b,c,d,cod); } for(int i=0;i<=255;++i) if(pd[n][i]>ans) ans=pd[n][i]; cout<<ans; return 0; }

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

miners.cpp: In function 'void adauga(int, int, int, int, int, int)':
miners.cpp:16:9: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   16 |     if(a&&b==0||c&&d==0)
      |        ~^~~~~~
miners.cpp: In function 'int main()':
miners.cpp:61:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   61 |     cin>>n>>a+1;
      |             ~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...