Submission #419799

# Submission time Handle Problem Language Result Execution time Memory
419799 2021-06-07T13:09:20 Z amoo_safar Ancient Machine (JOI21_ancient_machine) C++17
100 / 100
84 ms 9820 KB
#include "Anna.h"
#include <bits/stdc++.h>

#define pb push_back

using namespace std;

typedef long long ll;

const int bl = 76;
const int Log = 53;
ll fib[bl];

void Send(vector<int> seq){
	while((int) seq.size() % bl != 0)
		seq.pb(0);
	ll cd = 0;
	for(int i = 0; i < (int) seq.size(); i += bl){
		int j = i + bl - 1;
		while(i <= j){
			if(seq[j] == 0){
				j--;
				continue;
			}
			cd += fib[j - i];
			j -= 2;
		}
		// cerr << "Sent : " << cd << '\n';
		// cerr << "SEQ : ";
		// for(int j = i; j < i + bl; j++) cerr << seq[j];
		// cerr << '\n';
		for(int c = 0; c < Log; c++){
			Send(cd & 1);
			cd >>= 1;
		}
	}
}

void Anna(int _n, vector<char> S){
	fib[0] = 1;
	fib[1] = 2;
	for(int i = 2; i < bl; i++) fib[i] = fib[i - 1] + fib[i - 2];

	vector<int> V(_n, 0), seq;
	int fl = 0, fly = 1;
	for(int i = _n - 1; i >= 0; i--){
		if(S[i] == 'Y') fly = 1;
		if(S[i] == 'Z' && fly == 1)
			V[i] = 1, fly = 0;
	}
	int i = 0;
	for(auto c : S){
		if(fl == 0 && c == 'X'){
			fl = 1;
			seq.pb(1);
			seq.pb(0);
		} else {
			seq.pb(fl ? V[i] : 0);
		}
		i ++;
	}
	Send(seq);
	// for(auto x : seq)
		// Send(x);
	// for(auto x : seq)
		// cerr << x;
	// cerr << '\n';
	
}
#include "Bruno.h"
#include <bits/stdc++.h>
#define pb push_back

using namespace std;

typedef long long ll;

const int bl = 76;
const int Log = 53;
ll fib2[bl];


void Bruno(int _n, int L, vector<int> C) {
	fib2[0] = 1;
	fib2[1] = 2;
	for(int i = 2; i < bl; i++) fib2[i] = fib2[i - 1] + fib2[i - 2];
	
	vector<int> B;
	for(int i = 0; i < L; i += Log){
		ll nw = 0;
		for(int j = i + Log - 1; j >= i; j--){
			nw = nw + nw + C[j];
		}
		// cerr << "Got : " << nw << '\n';
		int ln = bl;
		vector<int> V;
		while(ln > 0){
			if(nw >= fib2[ln - 1]){
				nw -= fib2[ln - 1];
				V.pb(1);
				ln --;
				if(ln)
					V.pb(0);
				ln --;
			} else {
				V.pb(0);
				ln --;
			}
		}
		reverse(V.begin(), V.end());
		for(auto x : V)
			B.pb(x);
	}
	
	// cerr << "!! ";
	// for(auto x : B) cerr << x; cerr << '\n'; 
	B.resize(_n + 1);
	L = B.size();
	for(int i = 0; i + 1 < L; i++)
		assert((B[i] == 0) || (B[i + 1] == 0));

	int fl = 0;
	vector<int> A;
	for(int i = 0; i < L; i++){
		if(B[i] == 0) A.pb(0);
		else {
			A.pb(1);
			if(!fl) i++;
			fl = 1;
		}
	}
	A.resize(_n, 0);
	L = _n;

	int cnt = 0;
	vector<int> mk(_n, 0);
	for (int i = 0; i < L; i++) {
		// cerr << "!" << A[i] << '\n';
		if(A[i] == 1){
			cnt ++;
			for(int j = i - 1; j >= 0; j--){
				if(A[j] == 1) break;
				Remove(j);
				mk[j] = 1;
			}
			if(cnt != 1){
				Remove(i);
				mk[i] = 1;
			};
		}
	}
	for(int i = 0; i < _n; i++) if(!mk[i]) Remove(i);
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 484 KB Output is correct
2 Correct 0 ms 488 KB Output is correct
3 Correct 1 ms 484 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 496 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 484 KB Output is correct
8 Correct 1 ms 484 KB Output is correct
9 Correct 0 ms 488 KB Output is correct
10 Correct 0 ms 484 KB Output is correct
11 Correct 0 ms 484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 9624 KB Output is correct
2 Correct 62 ms 9608 KB Output is correct
3 Correct 71 ms 9576 KB Output is correct
4 Correct 71 ms 9664 KB Output is correct
5 Correct 75 ms 9820 KB Output is correct
6 Correct 65 ms 9628 KB Output is correct
7 Correct 64 ms 9588 KB Output is correct
8 Correct 62 ms 9560 KB Output is correct
9 Correct 76 ms 9600 KB Output is correct
10 Correct 63 ms 9580 KB Output is correct
11 Correct 75 ms 9692 KB Output is correct
12 Correct 66 ms 9584 KB Output is correct
13 Correct 80 ms 9604 KB Output is correct
14 Correct 68 ms 9608 KB Output is correct
15 Correct 69 ms 9632 KB Output is correct
16 Correct 73 ms 9580 KB Output is correct
17 Correct 70 ms 9632 KB Output is correct
18 Correct 69 ms 9560 KB Output is correct
19 Correct 68 ms 9500 KB Output is correct
20 Correct 62 ms 9552 KB Output is correct
21 Correct 64 ms 9572 KB Output is correct
22 Correct 75 ms 9584 KB Output is correct
23 Correct 62 ms 9660 KB Output is correct
24 Correct 70 ms 9616 KB Output is correct
25 Correct 71 ms 9600 KB Output is correct
26 Correct 84 ms 9632 KB Output is correct
27 Correct 66 ms 9648 KB Output is correct
28 Correct 69 ms 9580 KB Output is correct
29 Correct 71 ms 9500 KB Output is correct
30 Correct 74 ms 9592 KB Output is correct
31 Correct 73 ms 9664 KB Output is correct
32 Correct 77 ms 9528 KB Output is correct
33 Correct 74 ms 9548 KB Output is correct