Submission #417461

#TimeUsernameProblemLanguageResultExecution timeMemory
417461errorgornAncient Machine (JOI21_ancient_machine)C++17
100 / 100
76 ms9336 KiB
#include "Anna.h" #include <bits/stdc++.h> using namespace std; #define ll long long #define ii pair<ll,ll> #define fi first #define se second #define endl '\n' #define puf push_front #define pof pop_front #define pub push_back #define pob pop_back #define lb lower_bound #define ub upper_bound #define rep(x,s,e) for (auto x=s-(s>e);x!=e-(s>e);(s<e?x++:x--)) #define all(x) (x).begin(),(x).end() #define sz(x) (int) (x).size() namespace { int n; string s; const int L=44; const int B=63; ll fibo[64]; } void Anna(int N, std::vector<char> S) { fibo[0]=1,fibo[1]=2; rep(x,2,64) fibo[x]=fibo[x-2]+fibo[x-1]; n=N; rep(x,0,n) s+=S[x]; int pos=0; rep(x,0,n) if (s[x]=='X'){ pos=x; break; } rep(x,0,17){ if (pos&1) Send(1); else Send(0); pos>>=1; } vector<int> v; rep(x,0,n){ if (s[x]=='Z'){ if (!v.empty() && v.back()==1) v.back()=0; v.pub(1); } else{ v.pub(0); } } while (sz(v)%B) v.pub(0); while (!v.empty()){ ll curr=0; rep(x,0,B){ if (v.back()==1) curr+=fibo[x]; v.pob(); } rep(x,0,L){ if (curr&1) Send(1); else Send(0); curr>>=1; } } }
#include "Bruno.h" #include <bits/stdc++.h> using namespace std; #define ll long long #define ii pair<ll,ll> #define fi first #define se second #define endl '\n' #define puf push_front #define pof pop_front #define pub push_back #define pob pop_back #define lb lower_bound #define ub upper_bound #define rep(x,s,e) for (auto x=s-(s>e);x!=e-(s>e);(s<e?x++:x--)) #define all(x) (x).begin(),(x).end() #define sz(x) (int) (x).size() namespace { int n,l; vector<int> a; string s; const int L=44; const int B=63; ll fibo[64]; vector<int> bits; } // namespace void Bruno(int N, int LL, std::vector<int> A) { fibo[0]=1,fibo[1]=2; rep(x,2,64) fibo[x]=fibo[x-2]+fibo[x-1]; n=N,l=LL,a=A; int pos=0; rep(x,0,17) pos+=a[x]*(1<<x); for (int x=l-L;x>=17;x-=L){ ll curr=0; rep(y,0,L){ curr+=a[x+y]*(1LL<<y); } rep(y,B,0){ if (curr>=fibo[y]){ curr-=fibo[y]; bits.pub(1); } else{ bits.pub(0); } } } vector<int> stk; rep(x,0,pos+1) stk.pub(x); rep(x,pos+1,n){ if (bits[x]){ while (stk.back()!=pos){ Remove(stk.back()); stk.pob(); } Remove(x); } else{ stk.pub(x); } } rep(x,0,sz(stk)) Remove(stk[x]); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...