답안 #330890

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
330890 2020-11-26T20:13:09 Z NachoLibre Broken Device (JOI17_broken_device) C++14
100 / 100
52 ms 3208 KB
#include <bits/stdc++.h>
using namespace std;
#define ANNACPP ANNACPP
// #define BRUNOCPP BRUNOCPP

#ifdef WEEE
#define ANNACPP ANNACPP
#define BRUNOCPP BRUNOCPP

int mc[150];
int gf[150];
void Set(int pos, int val) {
	if(gf[pos] && val) {
		cout << "[]!" << endl;
		exit(0);
	}
	mc[pos] = val;
}

#endif

#ifdef ANNACPP
#ifndef WEEE
#include "Annalib.h"
#endif

void Anna(int n, long long x, int k, int p[]) {
	vector<int> v, g;
	g.resize(n, 0);
	for(int i = 0; i < k; ++i) {
		g[p[i]] = 1;
	}
	int bt = 0;
	for(int i = 0; i < n; i += 3) {
		int jg = g[i] + g[i + 1] + g[i + 2];
		if(jg >= 2 || bt > 60) {
			v.push_back(0);
			v.push_back(0);
			v.push_back(0);
		} else if(jg == 0) {
			int tx = (((x & (1ll << bt)) << 1) | ((x & (1ll << (bt + 1))) >> 1)) >> bt;
			bt += 2;
			if(tx == 0) {
				v.push_back(0);
				v.push_back(0);
				v.push_back(1);
			} else if(tx == 1) {
				v.push_back(1);
				v.push_back(0);
				v.push_back(1);
			} else if(tx == 2) {
				v.push_back(1);
				v.push_back(1);
				v.push_back(0);
			} else if(tx == 3) {
				v.push_back(1);
				v.push_back(1);
				v.push_back(1);
			} else {
				exit(1);
			}
		} else if(jg == 1) {
			int tx = (x & (1ll << bt)) >> bt;
			++bt;
			if(tx == 0) {
				if(g[i + 1]) {
					tx = (x & (1ll << bt)) >> bt;
					++bt;
					if(tx == 0) {
						v.push_back(0);
						v.push_back(0);
						v.push_back(1);
					} else if(tx == 1) {
						v.push_back(1);
						v.push_back(0);
						v.push_back(1);
					} else {
						exit(1);
					}
				} else {
					v.push_back(0);
					v.push_back(1);
					v.push_back(0);
				}
			} else if(tx == 1) {
				if(g[i]) {
					v.push_back(0);
					v.push_back(1);
					v.push_back(1);
				} else {
					v.push_back(1);
					v.push_back(0);
					v.push_back(0);
				}
			} else {
				exit(1);
			}
		}
	}
	for(int i = 0; i < n; ++i) {
		Set(i, v[i]);
	}
}

#endif

#ifdef BRUNOCPP
#ifndef WEEE
#include "Brunolib.h"
#endif

long long Bruno(int n, int a[]) {
	long long x = 0;
	int bt = 0;
	for(int i = 0; i < n; i += 3) {
		int m = a[i] * 4 + a[i + 1] * 2 + a[i + 2];
		if(m == 0);
		else if(m == 1) bt += 2;
		else if(m == 2) ++bt;
		else if(m == 3) x |= (1ll << bt), ++bt;
		else if(m == 4) x |= (1ll << bt), ++bt;
		else if(m == 5) ++bt, x |= (1ll << bt), ++bt;
		else if(m == 6) x |= (1ll << bt), bt += 2;
		else if(m == 7) x |= (1ll << bt), ++bt, x |= (1ll << bt), ++bt;
	}
	return x;
}

#endif


#ifdef WEEE

mt19937_64 rnd(time(NULL));
long long mx = 1000000000000000001ll;
int a[150];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	while(true) {
		long long x = rnd() % mx;
		for(int i = 0; i < 150; ++i) {
			gf[i] = 0;
		}
		for(int i = 0; i < 40; ++i) {
			a[i] = rnd() % 150;
			gf[a[i]] = 1;
		}
		Anna(150, x, 40, a);
		long long y = Bruno(150, mc);
		if(x != y) {
			cout << x << " " << y << endl;
			exit(0);
		} else {
			cout << "[].\n" << flush;
		}
	}
	return 0;
}
#endif
#include <bits/stdc++.h>
using namespace std;
// #define ANNACPP ANNACPP
#define BRUNOCPP BRUNOCPP

#ifdef WEEE
#define ANNACPP ANNACPP
#define BRUNOCPP BRUNOCPP

int mc[150];
int gf[150];
void Set(int pos, int val) {
	if(gf[pos] && val) {
		cout << "[]!" << endl;
		exit(0);
	}
	mc[pos] = val;
}

#endif

#ifdef ANNACPP
#ifndef WEEE
#include "Annalib.h"
#endif

void Anna(int n, long long x, int k, int p[]) {
	vector<int> v, g;
	g.resize(n, 0);
	for(int i = 0; i < k; ++i) {
		g[p[i]] = 1;
	}
	int bt = 0;
	for(int i = 0; i < n; i += 3) {
		int jg = g[i] + g[i + 1] + g[i + 2];
		if(jg >= 2 || bt > 60) {
			v.push_back(0);
			v.push_back(0);
			v.push_back(0);
		} else if(jg == 0) {
			int tx = (((x & (1ll << bt)) << 1) | ((x & (1ll << (bt + 1))) >> 1)) >> bt;
			bt += 2;
			if(tx == 0) {
				v.push_back(0);
				v.push_back(0);
				v.push_back(1);
			} else if(tx == 1) {
				v.push_back(1);
				v.push_back(0);
				v.push_back(1);
			} else if(tx == 2) {
				v.push_back(1);
				v.push_back(1);
				v.push_back(0);
			} else if(tx == 3) {
				v.push_back(1);
				v.push_back(1);
				v.push_back(1);
			} else {
				exit(1);
			}
		} else if(jg == 1) {
			int tx = (x & (1ll << bt)) >> bt;
			++bt;
			if(tx == 0) {
				if(g[i + 1]) {
					tx = (x & (1ll << bt)) >> bt;
					++bt;
					if(tx == 0) {
						v.push_back(0);
						v.push_back(0);
						v.push_back(1);
					} else if(tx == 1) {
						v.push_back(1);
						v.push_back(0);
						v.push_back(1);
					} else {
						exit(1);
					}
				} else {
					v.push_back(0);
					v.push_back(1);
					v.push_back(0);
				}
			} else if(tx == 1) {
				if(g[i]) {
					v.push_back(0);
					v.push_back(1);
					v.push_back(1);
				} else {
					v.push_back(1);
					v.push_back(0);
					v.push_back(0);
				}
			} else {
				exit(1);
			}
		}
	}
	for(int i = 0; i < n; ++i) {
		Set(i, v[i]);
	}
}

#endif

#ifdef BRUNOCPP
#ifndef WEEE
#include "Brunolib.h"
#endif

long long Bruno(int n, int a[]) {
	long long x = 0;
	int bt = 0;
	for(int i = 0; i < n; i += 3) {
		int m = a[i] * 4 + a[i + 1] * 2 + a[i + 2];
		if(m == 0);
		else if(m == 1) bt += 2;
		else if(m == 2) ++bt;
		else if(m == 3) x |= (1ll << bt), ++bt;
		else if(m == 4) x |= (1ll << bt), ++bt;
		else if(m == 5) ++bt, x |= (1ll << bt), ++bt;
		else if(m == 6) x |= (1ll << bt), bt += 2;
		else if(m == 7) x |= (1ll << bt), ++bt, x |= (1ll << bt), ++bt;
	}
	return x;
}

#endif


#ifdef WEEE

mt19937_64 rnd(time(NULL));
long long mx = 1000000000000000001ll;
int a[150];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	while(true) {
		long long x = rnd() % mx;
		for(int i = 0; i < 150; ++i) {
			gf[i] = 0;
		}
		for(int i = 0; i < 40; ++i) {
			a[i] = rnd() % 150;
			gf[a[i]] = 1;
		}
		Anna(150, x, 40, a);
		long long y = Bruno(150, mc);
		if(x != y) {
			cout << x << " " << y << endl;
			exit(0);
		} else {
			cout << "[].\n" << flush;
		}
	}
	return 0;
}
#endif
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 2884 KB Output is correct - L* = 40
2 Correct 43 ms 2736 KB Output is correct - L* = 40
3 Correct 40 ms 2740 KB Output is correct - L* = 40
4 Correct 52 ms 2944 KB Output is correct - L* = 40
5 Correct 41 ms 3000 KB Output is correct - L* = 40
6 Correct 40 ms 2744 KB Output is correct - L* = 40
7 Correct 45 ms 2744 KB Output is correct - L* = 40
8 Correct 40 ms 2944 KB Output is correct - L* = 40
9 Correct 40 ms 2744 KB Output is correct - L* = 40
10 Correct 52 ms 2952 KB Output is correct - L* = 40
11 Correct 41 ms 2952 KB Output is correct - L* = 40
12 Correct 40 ms 2952 KB Output is correct - L* = 40
13 Correct 40 ms 2744 KB Output is correct - L* = 40
14 Correct 40 ms 2868 KB Output is correct - L* = 40
15 Correct 40 ms 2836 KB Output is correct - L* = 40
16 Correct 43 ms 2744 KB Output is correct - L* = 40
17 Correct 40 ms 2944 KB Output is correct - L* = 40
18 Correct 41 ms 2952 KB Output is correct - L* = 40
19 Correct 40 ms 2844 KB Output is correct - L* = 40
20 Correct 40 ms 2872 KB Output is correct - L* = 40
21 Correct 40 ms 3208 KB Output is correct - L* = 40
22 Correct 43 ms 2772 KB Output is correct - L* = 40
23 Correct 40 ms 2952 KB Output is correct - L* = 40
24 Correct 40 ms 2872 KB Output is correct - L* = 40
25 Correct 40 ms 2744 KB Output is correct - L* = 40
26 Correct 43 ms 2944 KB Output is correct - L* = 40
27 Correct 41 ms 2872 KB Output is correct - L* = 40
28 Correct 40 ms 2944 KB Output is correct - L* = 40
29 Correct 41 ms 2944 KB Output is correct - L* = 40
30 Correct 41 ms 2872 KB Output is correct - L* = 40
31 Correct 40 ms 2944 KB Output is correct - L* = 40
32 Correct 40 ms 2944 KB Output is correct - L* = 40
33 Correct 43 ms 2944 KB Output is correct - L* = 40
34 Correct 40 ms 2868 KB Output is correct - L* = 40
35 Correct 41 ms 2872 KB Output is correct - L* = 40
36 Correct 40 ms 2872 KB Output is correct - L* = 40
37 Correct 40 ms 2744 KB Output is correct - L* = 40
38 Correct 40 ms 2740 KB Output is correct - L* = 40
39 Correct 40 ms 2868 KB Output is correct - L* = 40
40 Correct 40 ms 2872 KB Output is correct - L* = 40