답안 #496268

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
496268 2021-12-21T04:27:14 Z minhcool Ancient Machine (JOI21_ancient_machine) C++17
83 / 100
60 ms 8396 KB
#include "Anna.h"
#include<bits/stdc++.h>
using namespace std;
 
//#define int long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define foru(i, l, r) for(int i = l; i <= r; i++)
#define ford(i, r, l) for(int i = r; i >= l; i--)
 
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
 
//const int oo = 1e18 + 7, mod = 1e9 + 7;
 
int ret[100005];
 
void Anna(int n, vector<char> S){
	int need = 0, occ = 0, pos = -1;
	for(int i = n - 1; i >= 0; i--){
		if(S[i] == 'Z' && !occ){
			occ = 1;
			pos = i;
			ret[i] = 1;
		}
		else if(S[i] == 'X' && occ && (!i || S[i - 1] != 'X')){
			ret[i] = 1;
		}
	}
	//for(int i = 0; i < n; i++) Send(ret[i]);
	// Step 1: encode the position of 'Z'
	if(pos == -1) return;
	for(int i = 0; i < 19; i++){
		if(pos & (1LL << i)) Send(1);
		else Send(0);
	}
	Send(pos >= 2 && S[pos - 1] == 'X' && S[pos - 2] != 'X');
	for(int i = pos - 2; i >= 0; i -= 10){
		if(i <= 9){
			for(int j = i; j >= 0; j--){
				if(S[j] == 'X' && (!j || S[j - 1] != 'X')) Send(1);
				else Send(0);
			}	
		}
		else{
			int tol = 0;
			for(int j = 0; j < 5; j++){
				int temp1 = i - 2 * j, temp2 = i - 2 * j - 1;
				if(S[temp1] == 'X' && S[temp1 - 1] != 'X') tol = (tol * 3 + 1);
				else if(S[temp2] == 'X' && S[temp2 - 1] != 'X') tol = (tol * 3 + 2);
				else tol = (tol * 3);
			}
			for(int j = 0; j < 8; j++){
				if(tol & (1LL << j)) Send(1);
				else Send(0);
			}
		}
	}
}
/*
void process(){
 
}
 
signed main(){
	ios_base::sync_with_stdio(0);
	process();
}*/
#include<bits/stdc++.h>
#include "Bruno.h"
using namespace std;
 
//#define int long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define foru(i, l, r) for(int i = l; i <= r; i++)
#define ford(i, r, l) for(int i = r; i >= l; i--)
 
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
 
//const int N = 1e5 + 5;
 
//const int oo = 1e18 + 7, mod = 1e9 + 7;

int a[100005];

void decode(vector<int> B){
	if(!B.size()) return;
	int pos = 0;
	for(int i = 0; i < 19; i++){
		if(B[i] == 1) pos += (1LL << i);
	}
	if(pos <= 1) return;
	//cout << pos << "\n";
	//return;
	a[pos] = 1;
	if(B[19]) a[pos - 1] = 1;
	int itr = 20;
	for(int i = pos - 2; i >= 0; i -= 10){
		if(i >= 10){
			int tol = 0;
			for(int j = itr; j < itr + 8; j++){
				if(B[j]) tol += (1LL << (j - itr));
			}
			for(int j = 4; j >= 0; j--){
				int temp1 = i - 2 * j, temp2 = i - 2 * j - 1;
				if(tol % 3 == 1) a[temp1] = 1;
				if(tol % 3 == 2) a[temp2] = 1;
				tol /= 3;
			}
			itr += 8;
		}
		else{
			int tol = 0;
			for(int j = i; j >= 0; j--){
				a[j] = B[itr];
				itr++;
			}
		}
	}
}
 
void Bruno(int N, int L, vector<int> B){
	//cout << B.size() << "\n";
	//for(int i = 0; i < N; i++) Remove(i);
	decode(B);
	//return;
	//cout << N << " " << L << "\n";
	vector<int> not_rev;
	int pos = -1;
	for(int i = N - 1; i >= 0; i--){
		if(a[i]){
			pos = i;
			break;
		}
	}
	if(pos == -1){
		for(int i = 0; i < N; i++) Remove(i);
		return;
	}
	int lst = pos;
	for(int i = pos - 1; i >= 0; i--){
		if(!i || a[i]){
			for(int j = i + 1; j < lst; j++) Remove(j);
			Remove(i);
			lst = i;
		}
		//Remove(i);
	}
	for(int i = pos; i < N; i++) Remove(i);
}
 
/*
void process(){
 
}
 
signed main(){
	ios_base::sync_with_stdio(0);
	process();
}*/

Compilation message

Anna.cpp: In function 'void Anna(int, std::vector<char>)':
Anna.cpp:22:6: warning: unused variable 'need' [-Wunused-variable]
   22 |  int need = 0, occ = 0, pos = -1;
      |      ^~~~

Bruno.cpp: In function 'void decode(std::vector<int>)':
Bruno.cpp:50:8: warning: unused variable 'tol' [-Wunused-variable]
   50 |    int tol = 0;
      |        ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 500 KB Output is correct
2 Correct 0 ms 488 KB Output is correct
3 Correct 0 ms 492 KB Output is correct
4 Correct 0 ms 492 KB Output is correct
5 Correct 2 ms 488 KB Output is correct
6 Correct 0 ms 528 KB Output is correct
7 Correct 0 ms 496 KB Output is correct
8 Correct 0 ms 492 KB Output is correct
9 Correct 0 ms 488 KB Output is correct
10 Correct 1 ms 488 KB Output is correct
11 Correct 0 ms 496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 47 ms 8324 KB Partially correct
2 Partially correct 46 ms 8396 KB Partially correct
3 Partially correct 49 ms 8384 KB Partially correct
4 Partially correct 49 ms 8352 KB Partially correct
5 Partially correct 47 ms 8308 KB Partially correct
6 Partially correct 48 ms 8348 KB Partially correct
7 Partially correct 47 ms 8288 KB Partially correct
8 Partially correct 47 ms 8268 KB Partially correct
9 Partially correct 46 ms 8288 KB Partially correct
10 Partially correct 48 ms 8292 KB Partially correct
11 Partially correct 47 ms 8332 KB Partially correct
12 Partially correct 48 ms 8268 KB Partially correct
13 Partially correct 59 ms 8316 KB Partially correct
14 Partially correct 60 ms 7668 KB Partially correct
15 Partially correct 52 ms 8220 KB Partially correct
16 Partially correct 53 ms 8228 KB Partially correct
17 Correct 43 ms 6432 KB Output is correct
18 Correct 43 ms 6500 KB Output is correct
19 Partially correct 54 ms 7496 KB Partially correct
20 Partially correct 46 ms 8268 KB Partially correct
21 Partially correct 45 ms 8260 KB Partially correct
22 Partially correct 53 ms 7584 KB Partially correct
23 Partially correct 54 ms 8252 KB Partially correct
24 Partially correct 46 ms 8320 KB Partially correct
25 Partially correct 54 ms 7540 KB Partially correct
26 Correct 43 ms 6356 KB Output is correct
27 Correct 41 ms 6456 KB Output is correct
28 Correct 45 ms 6356 KB Output is correct
29 Correct 41 ms 6372 KB Output is correct
30 Correct 43 ms 6452 KB Output is correct
31 Partially correct 53 ms 7464 KB Partially correct
32 Partially correct 47 ms 8340 KB Partially correct
33 Partially correct 50 ms 8364 KB Partially correct