답안 #524660

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
524660 2022-02-09T18:19:30 Z amunduzbaev Ancient Machine (JOI21_ancient_machine) C++17
100 / 100
57 ms 8328 KB
#include "Anna.h"
#include "bits/stdc++.h"
using namespace std;
 
#define ll __int128

const int B = 93;
const ll one = (ll)1;
const ll b = 65;
ll dp[B][2];

void Anna(int n, vector<char> s) {
	int f = -1;
	for(int i=0;i<n;i++){
		if(s[i] == 'X') { f = i; break; }
	}
	
	int C = (n + B - 1) / B;
	if(f == -1){
		return;
	}
	
	for(int i=0;i<17;i++) Send(f >> i & 1);
	
	vector<int> res(n);
	//~ res[f] = 1;
	for(int i=f+1;i<n;i++){
		if(s[i] == 'Z'){
			res[i] = 1;
			if(s[i-1] == 'Z') res[i-1] = 0;
		}
	}
	
	dp[0][0] = dp[0][1] = 1;
	for(int i=1;i<B;i++){
		dp[i][0] = dp[i-1][0] + dp[i-1][1];
		dp[i][1] = dp[i-1][0];
	}
	
	//~ auto get = [&](vector<int> x) {
		//~ ii res = (ii)0;
		//~ for(int i=0;i<(int)x.size();i++){
			//~ if(x[i]) res += dp[i][0];
		//~ } return res;
	//~ };
	//~ for(int i=0;i<n;i++) cout<<res[i]<<" ";
	//~ cout<<"\n";
	
	vector<int> rr;
	for(int i=0;i<C;i++){
		vector<int> tmp = vector<int>(res.begin() + i * B, res.begin() + min(n, (i + 1) * B));
		ll v = 0;
		for(int i=0;i<(int)tmp.size();i++){
			if(tmp[i]) v = v + dp[i][0];
		} 
		
		for(int j=0;j<b;j++){
			Send(v >> j & 1);
		}
	}
}
#include "Bruno.h"
#include "bits/stdc++.h"
using namespace std;

#define ll __int128
const int B = 93;
const ll one = (ll)1;
const ll b = 65;

void Bruno(int n, int l, vector<int> a) {
	ll dp[B][2] {};
	dp[0][0] = dp[0][1] = 1;
	for(int i=1;i<B;i++){
		dp[i][0] = dp[i-1][0] + dp[i-1][1];
		dp[i][1] = dp[i-1][0];
	}
	
	if(!l){
		for(int i=0;i<n;i++) Remove(i);
		return;
	}
	
	int f = 0;
	for(int i=0;i<17;i++) f |= (a[i] << i);
	a.erase(a.begin(), a.begin() + 17);
	//~ cout<<f<<endl;
	
	int C = (n + B - 1) / B;
	vector<int> is(C * B);
	for(int i=0;i<C;i++){
		ll v = 0;
		for(int j=i*b;j<(i+1)*b;j++){
			v |= ((a[j] * one) << (j - i*b));
		}
		
		for(int l=B-1;~l;l--){
			if(v >= dp[l][0]) is[i * B + l] = 1, v -= dp[l][0];
		}
		
		//~ cout<<"here"<<endl;
	}
	
	for(int i=0;i<f;i++) Remove(i);
	int last = f; //, f = -1;
	for(int i=f+1;i<n;i++){
		if(is[i]){
			int j = i - 1;
			while(j > last) Remove(j--);
			Remove(i); last = i;
		}
	}
	
	int j = n - 1;
	while(j > last) Remove(j--);
	Remove(f);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 484 KB Output is correct
2 Correct 0 ms 484 KB Output is correct
3 Correct 0 ms 484 KB Output is correct
4 Correct 0 ms 492 KB Output is correct
5 Correct 0 ms 484 KB Output is correct
6 Correct 0 ms 492 KB Output is correct
7 Correct 0 ms 496 KB Output is correct
8 Correct 0 ms 484 KB Output is correct
9 Correct 0 ms 484 KB Output is correct
10 Correct 0 ms 492 KB Output is correct
11 Correct 0 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 51 ms 7928 KB Output is correct
2 Correct 47 ms 8124 KB Output is correct
3 Correct 48 ms 8096 KB Output is correct
4 Correct 49 ms 8328 KB Output is correct
5 Correct 47 ms 8176 KB Output is correct
6 Correct 47 ms 8192 KB Output is correct
7 Correct 48 ms 8184 KB Output is correct
8 Correct 48 ms 8116 KB Output is correct
9 Correct 47 ms 8224 KB Output is correct
10 Correct 47 ms 8144 KB Output is correct
11 Correct 47 ms 8152 KB Output is correct
12 Correct 48 ms 8124 KB Output is correct
13 Correct 57 ms 8136 KB Output is correct
14 Correct 53 ms 8148 KB Output is correct
15 Correct 47 ms 8228 KB Output is correct
16 Correct 48 ms 8132 KB Output is correct
17 Correct 53 ms 8168 KB Output is correct
18 Correct 46 ms 6704 KB Output is correct
19 Correct 45 ms 6664 KB Output is correct
20 Correct 46 ms 8144 KB Output is correct
21 Correct 46 ms 8108 KB Output is correct
22 Correct 56 ms 8108 KB Output is correct
23 Correct 48 ms 8124 KB Output is correct
24 Correct 47 ms 8144 KB Output is correct
25 Correct 44 ms 6696 KB Output is correct
26 Correct 54 ms 8120 KB Output is correct
27 Correct 54 ms 8112 KB Output is correct
28 Correct 54 ms 8236 KB Output is correct
29 Correct 41 ms 6704 KB Output is correct
30 Correct 53 ms 8224 KB Output is correct
31 Correct 44 ms 6680 KB Output is correct
32 Correct 47 ms 8188 KB Output is correct
33 Correct 49 ms 8152 KB Output is correct