답안 #1048862

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1048862 2024-08-08T10:01:01 Z AmirAli_H1 레지스터 (IOI21_registers) C++17
60 / 100
1 ms 788 KB
// In the name of Allah

#include <bits/stdc++.h>
#include "registers.h"
using namespace std;

typedef		long long				ll;
typedef		long double				ld;
typedef		pair<int, int>			pii;
typedef		pair<ll, ll>			pll;

#define		endl					'\n'
#define		sep						' '
#define		F						first
#define		S						second
#define		all(x)					(x).begin(),(x).end()
#define		len(x)					((ll) (x).size())
#define		pb						push_back
#define		Mp						make_pair

const int M = 100;

int n, k, q, R, Rx;
vector<bool> vc;

void solve(int md, int n, int k) {
	if (n == 1) {
		if (md == 1) {
			append_left(0, 0, R * k);
			append_or(M - 23, M - 23, 0);
		}
		R++;
		return ;
	}
	
	int j = (n / 2) * (2 * k);
	append_right(1, 0, j);
	vc.clear(); vc.resize(2000);
	for (int i = 0; i < j; i++) vc[i] = 1;
	append_store(2, vc); append_and(0, 0, 2);
	
	int m = (n / 2); n -= m;
	append_xor(2, 0, M - 3);
	append_add(2, 2, M - 4);
	append_add(3, 1, 2);
	
	append_and(3, 3, M - 5);
	append_right(3, 3, k);
	append_left(4, 3, 2 * k);
	
	append_not(3, 3); append_add(3, 3, M - 6);
	
	append_add(3, 3, 4);
	append_not(4, 3);
	
	append_and(5, 0, 3);
	append_and(6, 1, 4);
	if (md == 1) {
		append_and(7, 0, 4);
		append_and(8, 1, 3);
	}
	
	append_or(0, 5, 6);
	if (md == 1) {
		append_or(1, 7, 8);
		append_left(1, 1, Rx * (2 * k));
		append_or(10, 10, 1);
	}
	
	Rx += m;
	solve(md, n, k);
}

void solvex() {
	vc.clear(); vc.resize(2000);
	for (int i = 0; i < k; i++) vc[i] = 1;
	append_store(M - 1, vc);
	
	vc.clear(); vc.resize(2000); vc[0] = 1;
	append_store(M - 2, vc);
	
	append_move(4, 0);
	
	append_right(1, 0, k);
	append_and(2, 0, M - 1);
	append_and(0, 1, 2);
	
	if (k == 1) return ;
	vc.clear(); vc.resize(2000);
	vc[0] = 0; vc[1] = 1; vc[2] = 1; vc[3] = 0;
	append_store(5, vc);
	append_xor(5, 4, 5); append_left(6, 5, 1000);
	append_not(5, 5); append_add(5, 5, M - 2);
	append_add(6, 5, 6);
	
	vc.clear(); vc.resize(2000);
	vc[0] = 1; vc[1] = 0; vc[2] = 0; vc[3] = 1;
	append_store(7, vc);
	append_xor(7, 4, 7); append_left(8, 7, 1000);
	append_not(7, 7); append_add(7, 7, M - 2);
	append_add(8, 7, 8);
	
	append_and(8, 6, 8); append_right(8, 8, 500);
	append_not(8, 8); append_and(8, 8, M - 2); append_or(0, 0, 8);
}

void construct_instructions(int md, int nx, int kx, int qx) {
	n = nx; k = kx; q = qx;
	if (md == 0 && n == 2 && k <= 2) {
		solvex();
		return ;
	}
	
	vc.clear(); vc.resize(2000);
	for (int i = 0; i < n * k; i++) {
		if (i % (2 * k) < k) vc[i] = 1;
	}
	append_store(M - 1, vc);
	
	vc.clear(); vc.resize(2000);
	for (int i = 0; i < n * k; i++) {
		if (i % (2 * k) >= k) vc[i] = 1;
	}
	append_store(M - 2, vc);
	
	vc.clear(); vc.resize(2000);
	for (int i = 0; i < 2000; i++) {
		if (i % (2 * k) <= k) vc[i] = 1;
	}
	append_store(M - 3, vc);
	
	vc.clear(); vc.resize(2000);
	for (int i = 0; i < 2000; i++) {
		if (i % (2 * k) == 0) vc[i] = 1;
	}
	append_store(M - 4, vc);
	
	vc.clear(); vc.resize(2000);
	for (int i = 0; i < 2000; i++) {
		if (i % (2 * k) == k) vc[i] = 1;
	}
	append_store(M - 5, vc);
	
	vc.clear(); vc.resize(2000); vc[0] = 1;
	append_store(M - 6, vc);
	
	vc.clear(); vc.resize(2000);
	for (int i = 0; i < n * k; i++) vc[i] = 1;
	append_store(M - 7, vc);
	
	append_xor(0, 0, M - 7);
	
	append_and(1, 0, M - 1); append_and(2, 0, M - 2);
	int j = n * k;
	if (n % 2 == 1) j += k;
	append_left(2, 2, j - k);
	
	append_or(0, 1, 2);
	
	if (md == 0) solve(md, n, k);
	else {
		R = 0;
		for (int i = n; i >= 1; i--) {
			Rx = 0;
			solve(md, i, k);
			append_move(0, 10);
			append_left(10, 10, 2000);
		}
		append_move(0, M - 23);
	}
	
	append_xor(0, 0, M - 7);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Wrong answer detected in grader
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 1 ms 788 KB Wrong answer detected in grader
4 Halted 0 ms 0 KB -