Submission #419553

# Submission time Handle Problem Language Result Execution time Memory
419553 2021-06-07T09:21:47 Z alishahali1382 Ancient Machine (JOI21_ancient_machine) C++17
100 / 100
87 ms 8708 KB
#include "Anna.h"
#include <bits/stdc++.h>
#pragma GCC optimize ("O2,unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) {cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;}
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const int inf=1000000010;
const ll INF=1000000000000001000LL;
const int mod=1000000007;
const int MAXN=100010, FIB=63, LOG=44;

ll fib[FIB+1];
bool A[MAXN];

string To_LOG(string S){
	ll res=0;
	for (int i=0; i<FIB; i++){
		if (S[i]=='1'){
			res+=fib[FIB-i-1];
			i++;
		}
	}
	// debug(res)
	string out="";
	for (int i=0; i<LOG; i++) out+=(res>>i&1)+'0';
	return out;
}

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

	// To_LOG("000000000000000000000000000000000000000000000000000000000000000");
	// To_LOG("000000000000000000000000000000000000000000000000000000000000001");
	// To_LOG("000000000000000000000000000000000000000000000000000000000000010");
	// To_LOG("000000000000000000000000000000000000000000000000000000000000100");
	// To_LOG("000000000000000000000000000000000000000000000000000000000000101");

	int posx=n;
	for (int i=0; i<n; i++) if (S[i]=='X'){
		posx=i;
		break ;
	}
	for (int i=0; i<17; i++) Send(posx>>i&1);
	// for (int i=0; i<posx; i++) Send(1);
	vector<int> vec;
	for (int i=posx; i<n; i++){
		if (S[i]=='Z'){
			if (i+1<n && S[i+1]=='Z') vec.pb(0);
			else vec.pb(1);
		}
		else vec.pb(0);
	}
	while (vec.size()%FIB) vec.pb(0);
	string out="";
	for (int i=0; i<vec.size();){
		string S="";
		for (int j=0; j<FIB; j++) S+='0'+vec[i++];
		out+=To_LOG(S);
		// debug2(S, To_LOG(S))

	}
	for (char ch:out) Send(ch-'0');
}

#include "Bruno.h"
#include <bits/stdc++.h>
#pragma GCC optimize ("O2,unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) {cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;}
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const int inf=1000000010;
const ll INF=1000000000000001000LL;
const int mod=1000000007;
const int MAXN=100010, FIB=63, LOG=44;

int n, m, k, u, v, x, y, t, a, b, ans;
char S[MAXN];
int stk[MAXN], sz;
bool mark[MAXN];
ll fib2[FIB+1];

inline void Rem(int x){
//	debug(x)
//	if (mark[x]) debug("fuck")
	Remove(x);
	mark[x]=1;
}

string ToFIB(string S){
	// reverse(all(S));
	ll res=0;
	for (int i=0; i<LOG; i++) if (S[i]=='1') res+=(1ll<<i);
	string out="";
	for (int i=0; i<FIB; i++){
		if (res>=fib2[FIB-i-1]){
			out+="1";
			res-=fib2[FIB-i-1];
			i++;
			if (i<FIB) out+="0";
		}
		else out+="0";
	}
	return out;
}

void Bruno(int n, int m, vector<int> A){
	fib2[0]=1;
	fib2[1]=2;
	for (int i=2; i<=FIB; i++) fib2[i]=fib2[i-1]+fib2[i-2];
	
	// debug(ToFIB("10010000100101010110100110110100111000100100"))
	// debug(ToFIB("00000000000000000000000000000000000000000001"))
	// debug(ToFIB("00000000000000000000000000000000000000000010"))
	// debug(ToFIB("00000000000000000000000000000000000000000011"))

	int posx=0;
	for (int i=0; i<17; i++) posx|=(A[i]<<i);
	for (int i=0; i<posx; i++) Rem(i);
	
	string B="";
	for (int i=17; i<m; ){
		string S="";
		for (int j=0; j<LOG; j++) S+='0'+A[i++];
		B+=ToFIB(S);
	}

	for (int i=posx; i<n; i++){
		if (B[i-posx]=='0'){
			stk[++sz]=i;
		}
		else{
			while (sz>1) Rem(stk[sz--]);
			Rem(i);
		}
	}
	while (sz) Rem(stk[sz--]);

	for (int i=0; i<n; i++) if (!mark[i]) Remove(i);
}

Compilation message

Anna.cpp: In function 'void Anna(int, std::vector<char>)':
Anna.cpp:71:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |  for (int i=0; i<vec.size();){
      |                ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 488 KB Output is correct
2 Correct 2 ms 520 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 484 KB Output is correct
5 Correct 0 ms 480 KB Output is correct
6 Correct 0 ms 484 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 0 ms 484 KB Output is correct
9 Correct 0 ms 484 KB Output is correct
10 Correct 1 ms 484 KB Output is correct
11 Correct 2 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 62 ms 8268 KB Output is correct
2 Correct 61 ms 8256 KB Output is correct
3 Correct 62 ms 8120 KB Output is correct
4 Correct 66 ms 8300 KB Output is correct
5 Correct 65 ms 8232 KB Output is correct
6 Correct 71 ms 8260 KB Output is correct
7 Correct 62 ms 8316 KB Output is correct
8 Correct 64 ms 8256 KB Output is correct
9 Correct 71 ms 8296 KB Output is correct
10 Correct 63 ms 8216 KB Output is correct
11 Correct 63 ms 8332 KB Output is correct
12 Correct 61 ms 8296 KB Output is correct
13 Correct 70 ms 8708 KB Output is correct
14 Correct 73 ms 8124 KB Output is correct
15 Correct 87 ms 8196 KB Output is correct
16 Correct 67 ms 8160 KB Output is correct
17 Correct 71 ms 8696 KB Output is correct
18 Correct 52 ms 6412 KB Output is correct
19 Correct 52 ms 6420 KB Output is correct
20 Correct 61 ms 8320 KB Output is correct
21 Correct 65 ms 8464 KB Output is correct
22 Correct 84 ms 8652 KB Output is correct
23 Correct 62 ms 8304 KB Output is correct
24 Correct 64 ms 8452 KB Output is correct
25 Correct 57 ms 6464 KB Output is correct
26 Correct 69 ms 8516 KB Output is correct
27 Correct 52 ms 6364 KB Output is correct
28 Correct 79 ms 8648 KB Output is correct
29 Correct 51 ms 6564 KB Output is correct
30 Correct 54 ms 6372 KB Output is correct
31 Correct 63 ms 6416 KB Output is correct
32 Correct 63 ms 8196 KB Output is correct
33 Correct 63 ms 8316 KB Output is correct