Submission #625026

#TimeUsernameProblemLanguageResultExecution timeMemory
625026andrei_boacaBoard (CEOI13_board)C++14
90 / 100
1089 ms1108 KiB
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; int a,b; string s; vector<int> val; vector<short> va,vb; void multiply() { int lg=val.size(); int last=lg%2; if(last==1) val.push_back(1); else val[lg-1]++; } void divide() { int lg=val.size(); int last=lg%2; if(val[lg-1]==1) val.pop_back(); else val[lg-1]--; } void add() { int lg=val.size(); int last=lg%2; if(last==0) { if(val[lg-1]>1) { val[lg-1]--; val.push_back(1); } else { val.pop_back(); lg--; val[lg-1]++; } return; } else { int nr1=val[lg-1]; int nr0=val[lg-2]; val.pop_back(); val.pop_back(); lg-=2; if(nr0==1) { val[lg-1]++; val.push_back(nr1); } else { nr0--; val.push_back(nr0); val.push_back(1); val.push_back(nr1); } } } void subtract() { int lg=val.size(); int last=lg%2; if(last==1) { if(val[lg-1]==1) { lg--; val.pop_back(); val[lg-1]++; } else { val[lg-1]--; val.push_back(1); } return; } else { int nr0=val[lg-1]; int nr1=val[lg-2]; val.pop_back(); val.pop_back(); lg-=2; if(nr1==1) { val[lg-1]++; val.push_back(nr0); } else { nr1--; val.push_back(nr1); val.push_back(1); val.push_back(nr0); } } } int getniv(int x) { for(int d=0;d<=62;d++) { int st=(1<<d); int dr=st*2-1; if(x>=st&&x<=dr) return d; } return -1; } vector<int> dif; void getdif() { dif.clear(); int t=0; for(int i=va.size()-1;i>=0;i--) { int x=va[i]-t-vb[i]; t=0; if(x<0) { x+=2; t=1; } dif.push_back(x); } while(!dif.empty()&&dif.back()==0) dif.pop_back(); if(dif.empty()) dif.push_back(0); reverse(dif.begin(),dif.end()); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin>>s; val.push_back(1); for(char c:s) { if(c=='1') multiply(); if(c=='2') { multiply(); add(); } if(c=='U') divide(); if(c=='L') subtract(); if(c=='R') add(); } for(int i=0;i<val.size();i++) { if(i%2==0) { for(int j=1;j<=val[i];j++) va.push_back(1); } else { for(int j=1;j<=val[i];j++) va.push_back(0); } } val.clear(); cin>>s; val.push_back(1); for(char c:s) { if(c=='1') multiply(); if(c=='2') { multiply(); add(); } if(c=='U') divide(); if(c=='L') subtract(); if(c=='R') add(); } for(int i=0;i<val.size();i++) { if(i%2==0) { for(int j=1;j<=val[i];j++) vb.push_back(1); } else { for(int j=1;j<=val[i];j++) vb.push_back(0); } } int rez=0; int ans=1e9; if(va.size()<vb.size()) swap(va,vb); while(va.size()>vb.size()) { rez++; va.pop_back(); } bool need=0; for(int i=0;i<va.size();i++) if(va[i]!=vb[i]) { if(va[i]<vb[i]) need=1; break; } if(need) swap(va,vb); /*for(int i:va) cout<<i; cout<<'\n'; for(int i:vb) cout<<i; cout<<'\n';*/ getdif(); while(dif.size()>3) { dif.pop_back(); va.pop_back(); vb.pop_back(); rez+=2; } while(dif.size()) { getdif(); int x=0; for(int i:dif) x=x*2+i; ans=min(ans,x+rez); if(x==0) break; rez+=2; va.pop_back(); vb.pop_back(); } cout<<ans; return 0; }

Compilation message (stderr)

board.cpp: In function 'void divide()':
board.cpp:20:9: warning: unused variable 'last' [-Wunused-variable]
   20 |     int last=lg%2;
      |         ^~~~
board.cpp: In function 'int main()':
board.cpp:161:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  161 |     for(int i=0;i<val.size();i++)
      |                 ~^~~~~~~~~~~
board.cpp:193:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  193 |     for(int i=0;i<val.size();i++)
      |                 ~^~~~~~~~~~~
board.cpp:216:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<short int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  216 |     for(int i=0;i<va.size();i++)
      |                 ~^~~~~~~~~~
#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...