Submission #417461

# Submission time Handle Problem Language Result Execution time Memory
417461 2021-06-03T18:23:40 Z errorgorn Ancient Machine (JOI21_ancient_machine) C++17
100 / 100
76 ms 9336 KB
#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 time Memory Grader output
1 Correct 1 ms 484 KB Output is correct
2 Correct 1 ms 484 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 2 ms 492 KB Output is correct
6 Correct 1 ms 484 KB Output is correct
7 Correct 1 ms 496 KB Output is correct
8 Correct 0 ms 484 KB Output is correct
9 Correct 1 ms 484 KB Output is correct
10 Correct 1 ms 484 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 75 ms 8804 KB Output is correct
2 Correct 64 ms 9152 KB Output is correct
3 Correct 60 ms 9144 KB Output is correct
4 Correct 61 ms 9168 KB Output is correct
5 Correct 62 ms 9204 KB Output is correct
6 Correct 61 ms 9196 KB Output is correct
7 Correct 61 ms 9156 KB Output is correct
8 Correct 60 ms 9080 KB Output is correct
9 Correct 60 ms 9180 KB Output is correct
10 Correct 59 ms 9160 KB Output is correct
11 Correct 60 ms 9200 KB Output is correct
12 Correct 64 ms 9108 KB Output is correct
13 Correct 66 ms 9256 KB Output is correct
14 Correct 67 ms 9224 KB Output is correct
15 Correct 63 ms 9220 KB Output is correct
16 Correct 62 ms 9072 KB Output is correct
17 Correct 67 ms 9224 KB Output is correct
18 Correct 67 ms 9300 KB Output is correct
19 Correct 66 ms 9204 KB Output is correct
20 Correct 69 ms 9216 KB Output is correct
21 Correct 60 ms 9168 KB Output is correct
22 Correct 67 ms 9308 KB Output is correct
23 Correct 65 ms 9164 KB Output is correct
24 Correct 59 ms 9252 KB Output is correct
25 Correct 66 ms 9276 KB Output is correct
26 Correct 67 ms 9336 KB Output is correct
27 Correct 76 ms 9308 KB Output is correct
28 Correct 67 ms 9320 KB Output is correct
29 Correct 67 ms 9236 KB Output is correct
30 Correct 69 ms 9312 KB Output is correct
31 Correct 69 ms 9184 KB Output is correct
32 Correct 59 ms 9116 KB Output is correct
33 Correct 62 ms 9148 KB Output is correct