Submission #874857

#TimeUsernameProblemLanguageResultExecution timeMemory
874857josanneo22Miners (IOI07_miners)C++17
100 / 100
49 ms1112 KiB
/* Problem: IOI 2007 Miners When: 2023-11-13 21:27:07 Author: JN */ #include<bits/stdc++.h> using namespace std; using i64 = long long; using pii = pair<int, int>; #define L(i,j,k) for(int i=(j);i<=(k);++i) #define R(i,j,k) for(int i=(j);i>=(k);--i) #define all(x) x.begin(), x.end() int dp[2][4][4][4][4]; namespace fast{ #pragma GCC optimize(Ofast) #pragma GCC optimization (unroll-loops) #pragma GCC target(avx,avx2,fma) #pragma GCC target(sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native) #pragma GCC optimize(3) #pragma GCC optimize("inline") #pragma GCC optimize("-fgcse") #pragma GCC optimize("-fgcse-lm") #pragma GCC optimize("-fipa-sra") #pragma GCC optimize("-ftree-pre") #pragma GCC optimize("-ftree-vrp") #pragma GCC optimize("-fpeephole2") #pragma GCC optimize("-ffast-math") #pragma GCC optimize("-fsched-spec") #pragma GCC optimize("unroll-loops") #pragma GCC optimize("-falign-jumps") #pragma GCC optimize("-falign-loops") #pragma GCC optimize("-falign-labels") #pragma GCC optimize("-fdevirtualize") #pragma GCC optimize("-fcaller-saves") #pragma GCC optimize("-fcrossjumping") #pragma GCC optimize("-fthread-jumps") #pragma GCC optimize("-funroll-loops") #pragma GCC optimize("-fwhole-program") #pragma GCC optimize("-freorder-blocks") #pragma GCC optimize("-fschedule-insns") #pragma GCC optimize("inline-functions") #pragma GCC optimize("-ftree-tail-merge") #pragma GCC optimize("-fschedule-insns2") #pragma GCC optimize("-fstrict-aliasing") #pragma GCC optimize("-fstrict-overflow") #pragma GCC optimize("-falign-functions") #pragma GCC optimize("-fcse-skip-blocks") #pragma GCC optimize("-fcse-follow-jumps") #pragma GCC optimize("-fsched-interblock") #pragma GCC optimize("-fpartial-inlining") #pragma GCC optimize("no-stack-protector") #pragma GCC optimize("-freorder-functions") #pragma GCC optimize("-findirect-inlining") #pragma GCC optimize("-fhoist-adjacent-loads") #pragma GCC optimize("-frerun-cse-after-loop") #pragma GCC optimize("inline-small-functions") #pragma GCC optimize("-finline-small-functions") #pragma GCC optimize("-ftree-switch-conversion") #pragma GCC optimize("-foptimize-sibling-calls") #pragma GCC optimize("-fexpensive-optimizations") #pragma GCC optimize("-funsafe-loop-optimizations") #pragma GCC optimize("inline-functions-called-once") #pragma GCC optimize("-fdelete-null-pointer-checks") } using namespace fast; inline string read_string(){ char ch=getchar(); string st1=""; while (!((ch>='A')&&(ch<='Z'))) ch=getchar(); while ((ch>='A')&&(ch<='Z')) st1+=ch,ch=getchar(); return st1; } template<typename T> inline void re(T &x){ x = 0; T f = 1; char ch = getchar(); while (!isdigit(ch)) {if (ch == '-') f = -1; ch = getchar();} while (isdigit(ch)) {x = (x<<1) + (x<<3) + (ch^48) ; ch = getchar();} x *= f; } template<typename x,typename... y>void re(x& a,y&... b){re(a);re(b...);} template<typename T> inline void ps(T x) { if(x < 0){ putchar('-'); x = -x; } if(x > 9) ps(x / 10); putchar(x % 10 + '0');} template<typename x,typename... y>void ps(x& a,y&... b){ps(a); putchar(' '); ps(b...);} #define sp putchar(' ') #define nl putchar('\n') const int N=1e5+500; char s[N]; int g[4][4][4]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n; re(n); string s=read_string(); vector<int> a(n+1); L(i,0,n-1){ if(s[i]=='M') a[i]=1; if(s[i]=='B') a[i]=2; if(s[i]=='F') a[i]=3; } memset(dp,-1,sizeof(dp)); dp[0][0][0][0][0]=0; auto find=[&](int x,int y,int z){ if(!x && !y) return 1; if(!x) return (y!=z)+1; if(x==y && y==z) return 1; return (x!=y)+(y!=z)+(z!=x); }; L(i,0,3) L(j,0,3) L(k,0,3) g[i][j][k]=find(i,j,k); auto profit=[&](int x,int y,int z){ return g[x][y][z]; }; L(i,0,n-1){ int nw=i&1;int nx=nw^1; L(a1,0,3) L(a2,0,3) L(b1,0,3) L(b2,0,3){ if(dp[nw][a1][a2][b1][b2]==-1) continue; dp[nx][a2][a[i]][b1][b2]=max(dp[nx][a2][a[i]][b1][b2], dp[nw][a1][a2][b1][b2]+profit(a1,a2,a[i])); dp[nx][a1][a2][b2][a[i]]=max(dp[nx][a1][a2][b2][a[i]], dp[nw][a1][a2][b1][b2]+profit(b1,b2,a[i])); // cout<<a1<<' '<<a2<<' '<<b1<<' '<<b2<<' '; // cout<<profit(a1,a2,a[i])<<' '; // cout<<profit(b1,b2,a[i])<<'\n'; } } int ans=0; L(a1,0,3) L(a2,0,3) L(b1,0,3) L(b2,0,3){ if(ans<dp[n&1][a1][a2][b1][b2]){ ans=dp[n&1][a1][a2][b1][b2]; //cout<<a1<<' '<<a2<<' '<<b1<<' '<<b2<<'\n'; } } ps(ans); }

Compilation message (stderr)

miners.cpp:19: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
   19 |     #pragma GCC optimization (unroll-loops)
      | 
miners.cpp:18:26: warning: '#pragma GCC optimize' is not a string or number [-Wpragmas]
   18 |     #pragma GCC optimize(Ofast)
      |                          ^~~~~
miners.cpp:20:24: warning: '#pragma GCC option' is not a string [-Wpragmas]
   20 |     #pragma GCC target(avx,avx2,fma)
      |                        ^~~
miners.cpp:21:24: warning: '#pragma GCC option' is not a string [-Wpragmas]
   21 |     #pragma GCC target(sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native)
      |                        ^~~
miners.cpp:41:43: warning: bad option '-fwhole-program' to pragma 'optimize' [-Wpragmas]
   41 |     #pragma GCC optimize("-fwhole-program")
      |                                           ^
miners.cpp:48:45: warning: bad option '-fstrict-overflow' to pragma 'optimize' [-Wpragmas]
   48 |     #pragma GCC optimize("-fstrict-overflow")
      |                                             ^
miners.cpp:50:45: warning: bad option '-fcse-skip-blocks' to pragma 'optimize' [-Wpragmas]
   50 |     #pragma GCC optimize("-fcse-skip-blocks")
      |                                             ^
miners.cpp:64:55: warning: bad option '-funsafe-loop-optimizations' to pragma 'optimize' [-Wpragmas]
   64 |     #pragma GCC optimize("-funsafe-loop-optimizations")
      |                                                       ^
miners.cpp:69:27: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
   69 | inline string read_string(){
      |                           ^
miners.cpp:69:27: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
miners.cpp:69:27: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
miners.cpp:69:27: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
miners.cpp:75:41: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
   75 | template<typename T> inline void re(T &x){ x = 0; T f = 1; char ch = getchar();  while (!isdigit(ch)) {if (ch == '-') f = -1; ch = getchar();} while (isdigit(ch))  {x = (x<<1) + (x<<3) + (ch^48) ; ch = getchar();} x *= f; }
      |                                         ^
miners.cpp:75:41: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
miners.cpp:75:41: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
miners.cpp:75:41: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
miners.cpp:76:55: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
   76 | template<typename x,typename... y>void re(x& a,y&... b){re(a);re(b...);}
      |                                                       ^
miners.cpp:76:55: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
miners.cpp:76:55: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
miners.cpp:76:55: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
miners.cpp:77:40: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
   77 | template<typename T> inline void ps(T x) { if(x < 0){ putchar('-'); x = -x; } if(x > 9)  ps(x / 10); putchar(x % 10 + '0');}
      |                                        ^
miners.cpp:77:40: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
miners.cpp:77:40: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
miners.cpp:77:40: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
miners.cpp:78:55: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
   78 | template<typename x,typename... y>void ps(x& a,y&... b){ps(a); putchar(' '); ps(b...);}
      |                                                       ^
miners.cpp:78:55: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
miners.cpp:78:55: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
miners.cpp:78:55: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
miners.cpp:85:10: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
   85 | int main() {
      |          ^
miners.cpp:85:10: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
miners.cpp:85:10: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
miners.cpp:85:10: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
miners.cpp: In function 'int main()':
miners.cpp:99:36: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
   99 |     auto find=[&](int x,int y,int z){
      |                                    ^
miners.cpp:99:36: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
miners.cpp:99:36: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
miners.cpp:99:36: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
miners.cpp:106:38: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
  106 |     auto profit=[&](int x,int y,int z){
      |                                      ^
miners.cpp:106:38: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
miners.cpp:106:38: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
miners.cpp:106:38: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
#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...