# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
950782 | Nhoksocqt1 | 레지스터 (IOI21_registers) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define sz(x) int((x).size())
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> ii;
template<class X, class Y>
inline bool maximize(X &x, const Y &y) {return (x < y ? x = y, 1 : 0);}
template<class X, class Y>
inline bool minimize(X &x, const Y &y) {return (x > y ? x = y, 1 : 0);}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int Random(int l, int r) {
return uniform_int_distribution<int>(l, r)(rng);
}
const int MAXM = 100;
const int MAXB = 2000;
int nArr, k, maxInstr;
#ifdef Nhoksocqt1
bool regs[MAXM][MAXB];
void append_move(int t, int x);
void append_store(int t, vector<bool> v);
void append_and(int t, int x, int y);
void append_or(int t, int x, int y);
void append_xor(int t, int x, int y);
void append_not(int t, int x);
void append_left(int t, int x, int p);
void append_right(int t, int x, int p);
void append_add(int t, int x, int y);
void append_print(int t);
#endif // Nhoksocqt1
void findMinElement(void) {
vector<bool> v(MAXB, 1);
append_store(1, v);
for (int i = k; i < MAXB; ++i)
v[i] = 0;
append_store(2, v);
append_and(10, 0, 2);
for (int i = 1; i < nArr; ++i) {
append_xor(9, 10, 1);
append_right(3, 0, i * k);
append_and(3, 3, 2);
append_add(4, 3, 9);
append_right(4, 4, MAXB - k);
append_and(3, 3, 4);
append_xor(4, 4, 2);
append_and(10, 10, 4);
append_or(10, 10, 3);
}
append_print(10);
}
void construct_instructions(int queryType, int _N, int _K, int _Q) {
nArr = _N, k = _K, maxInstr = _Q;
if(queryType == 0)
findMinElement();
}
#ifdef Nhoksocqt1
void append_move(int t, int x) {
assert(0 <= min({t, x}) && max({t, x}) < MAXB);
for (int i = 0; i < MAXB; ++i)
regs[t][i] = regs[x][i];
}
void append_store(int t, vector<bool> v) {
assert(sz(v) == MAXB);
assert(0 <= t && t < MAXB);
for (int i = 0; i < MAXB; ++i)
regs[t][i] = v[i];
}
void append_and(int t, int x, int y) {
assert(0 <= min({t, x, y}) && max({t, x, y}) < MAXB);
for (int i = 0; i < MAXB; ++i)
regs[t][i] = regs[x][i] & regs[y][i];
}
void append_or(int t, int x, int y) {
assert(0 <= min({t, x, y}) && max({t, x, y}) < MAXB);
for (int i = 0; i < MAXB; ++i)
regs[t][i] = regs[x][i] | regs[y][i];
}
void append_xor(int t, int x, int y) {
assert(0 <= min({t, x, y}) && max({t, x, y}) < MAXB);
for (int i = 0; i < MAXB; ++i)
regs[t][i] = regs[x][i] ^ regs[y][i];
}
void append_not(int t, int x) {
assert(0 <= min({t, x}) && max({t, x}) < MAXB);
for (int i = 0; i < MAXB; ++i)
regs[t][i] = 1 - regs[x][i];
}
void append_left(int t, int x, int p) {
assert(0 <= p && p <= MAXB);
assert(0 <= min({t, x}) && max({t, x}) < MAXB);
for (int i = 0; i < MAXB; ++i)
regs[t][i] = (i < p) ? 0 : regs[x][i - p];
}
void append_right(int t, int x, int p) {
assert(0 <= p && p <= MAXB);
assert(0 <= min({t, x}) && max({t, x}) < MAXB);
for (int i = 0; i < MAXB; ++i)
regs[t][i] = (i + p >= MAXB) ? 0 : regs[x][i + p];
}
void append_add(int t, int x, int y) {
assert(0 <= min({t, x, y}) && max({t, x, y}) < MAXB);
__int128 a(0), b(0), pw2(1);
for (int i = 0; i < MAXB; ++i) {
a += pw2 * regs[x][i];
b += pw2 * regs[y][i];
pw2 *= 2;
}
a += b;
for (int i = 0; i < MAXB; ++i) {
regs[t][i] = a % 2;
a /= 2;
}
}
void append_print(int t) {
cout << "ANSWER: ";
for (int i = 0; i < nArr; ++i) {
int res(0);
for (int j = 0; j < k; ++j)
res |= (1 << j) * regs[t][i * k + j];
cout << res << ' ';
}
cout << '\n';
}
int main(void) {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define TASK "registers"
if(fopen(TASK".inp", "r")) {
freopen(TASK".inp", "r", stdin);
freopen(TASK".out", "w", stdout);
}
int s, n, k, q;
cin >> s >> n >> k >> q;
for (int i = 0; i < n; ++i) {
int a;
cin >> a;
for (int j = 0; j < k; ++j)
regs[0][i * k + j] = (a >> j & 1);
}
construct_instructions(s, n, k, q);
return 0;
}
#endif // Nhoksocqt1