Submission #416952

# Submission time Handle Problem Language Result Execution time Memory
416952 2021-06-03T08:20:29 Z oolimry Ancient Machine (JOI21_ancient_machine) C++17
100 / 100
86 ms 8800 KB
#include "Anna.h"
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int) x.size())
#define show(x) cerr << #x << " is " << x << endl;
#define show2(x, y) cerr << #x << " is " << x << ", " << #y << " is " << y << endl;
typedef long long lint;
typedef pair<lint, lint> ii;

const int bin = 44, fib = 63;

vector<int> tosend;

lint dp[64];
void fibtobin(vector<int> F){
	lint res = 0;
	for(int i = 0;i < fib;){
		if(F[i] == 1){
			res += dp[fib-i-1];
			i += 2;
		}
		else i++;
	}
	
	for(int i = 0;i < bin;i++){
		tosend.push_back(res&1);
		res >>= 1;
	}
}

void Anna(int n, vector<char> s){	
	int X = -1;
	for(int i = 0;i < n;i++){
		if(s[i] == 'X'){
			X = i;
			break;
		}
	}
	
	dp[0] = 1, dp[1] = 2;
	for(int i = 2;i <= fib;i++) dp[i] = dp[i-1] + dp[i-2];
	if(X == -1) return;
	
	vector<int> original;
	for(int i = X+1;i < n;i++){
		if(s[i] == 'Z'){
			if(not original.empty() and original.back() == 1) original.back() = 0;
			original.push_back(1);
		}
		else original.push_back(0);
	}
	
	while(sz(original) % fib != 0) original.insert(original.begin(), 0);
	
	for(int i = 0;i < sz(original);i += fib){
		vector<int> f;
		for(int j = 0;j < fib;j++) f.push_back(original[i+j]);
		fibtobin(f);
	}
	
	for(int i = 0;i < 18;i++){
		tosend.push_back(X&1);
		X >>= 1;
	}
	
	for(int x : tosend) Send(x);
}
#include "Bruno.h"
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int) x.size())
#define show(x) cerr << #x << " is " << x << endl;
#define show2(x, y) cerr << #x << " is " << x << ", " << #y << " is " << y << endl;
typedef long long lint;
typedef pair<lint, lint> ii;

int nn;
int vis[100005];
void rem(int i){
	if(i > nn) return;
	Remove(i); vis[i] = 1;
}

lint DP[64];
vector<int> bintofib(vector<lint> B){
	lint res = 0;
	reverse(all(B));
	for(int x : B){
		res *= 2;
		res += x;
	}
	
	vector<int> F;
	
	for(int i = 0;i < 63;){
		if(res >= DP[63-i-1]){
			res -= DP[63-i-1];
			F.push_back(1);
			if(i != 63-1) F.push_back(0);
			i += 2;
		}
		else{
			i++;
			F.push_back(0);
		}
	}
	
	return F;
}

void Bruno(int n, int L, vector<int> A){
	nn = n;
	
	if(sz(A) == 0){
		for(int i = 0;i < n;i++) Remove(i);
		return;
	}
	
	DP[0] = 1, DP[1] = 2;
	for(int i = 2;i <= 63;i++) DP[i] = DP[i-1] + DP[i-2];
	
	int X = 0;
	for(int i = 0;i < 18;i++){
		X *= 2;
		X += A.back();
		A.pop_back();
	}
	
	vector<int> C;
	for(int i = 0;i < sz(A);i += 44){
		vector<lint> b;
		for(int j = 0;j < 44;j++) b.push_back(A[i+j]);
		
		vector<int> f = bintofib(b);
		for(int x : f) C.push_back(x);
	}
	
	while(sz(C) > n-X-1) C.erase(C.begin());
	
	int prev = X+1;
	for(int i = X+1;i < n;i++){
		int c = C[i-X-1];
		if(c == 1){
			for(int j = i-1;j >= prev;j--) rem(j);
			rem(i);
			prev = i+1;
		}
	}
	
	for(int i = 0;i < n;i++){
		if(not vis[i]) rem(i);
	}
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 484 KB Output is correct
2 Correct 1 ms 484 KB Output is correct
3 Correct 1 ms 484 KB Output is correct
4 Correct 1 ms 484 KB Output is correct
5 Correct 1 ms 480 KB Output is correct
6 Correct 1 ms 484 KB Output is correct
7 Correct 0 ms 484 KB Output is correct
8 Correct 1 ms 540 KB Output is correct
9 Correct 0 ms 484 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 0 ms 484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 64 ms 8732 KB Output is correct
2 Correct 65 ms 8700 KB Output is correct
3 Correct 64 ms 8760 KB Output is correct
4 Correct 73 ms 8680 KB Output is correct
5 Correct 65 ms 8636 KB Output is correct
6 Correct 65 ms 8688 KB Output is correct
7 Correct 68 ms 8772 KB Output is correct
8 Correct 68 ms 8664 KB Output is correct
9 Correct 63 ms 8684 KB Output is correct
10 Correct 65 ms 8600 KB Output is correct
11 Correct 63 ms 8800 KB Output is correct
12 Correct 69 ms 8752 KB Output is correct
13 Correct 70 ms 8712 KB Output is correct
14 Correct 72 ms 8704 KB Output is correct
15 Correct 73 ms 8660 KB Output is correct
16 Correct 70 ms 8688 KB Output is correct
17 Correct 73 ms 8732 KB Output is correct
18 Correct 54 ms 6352 KB Output is correct
19 Correct 54 ms 6444 KB Output is correct
20 Correct 81 ms 8688 KB Output is correct
21 Correct 66 ms 8776 KB Output is correct
22 Correct 71 ms 8596 KB Output is correct
23 Correct 64 ms 8720 KB Output is correct
24 Correct 74 ms 8608 KB Output is correct
25 Correct 52 ms 6280 KB Output is correct
26 Correct 74 ms 8688 KB Output is correct
27 Correct 52 ms 6820 KB Output is correct
28 Correct 86 ms 8708 KB Output is correct
29 Correct 51 ms 6288 KB Output is correct
30 Correct 56 ms 6732 KB Output is correct
31 Correct 55 ms 6360 KB Output is correct
32 Correct 80 ms 8644 KB Output is correct
33 Correct 70 ms 8660 KB Output is correct