QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#120142 | #6189. Full Clue Problem | hos_lyric | AC ✓ | 1ms | 3708kb | C++14 | 4.5kb | 2023-07-06 14:13:26 | 2023-07-06 14:13:27 |
Judging History
answer
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
vector<int> uf;
int root(int u) {
return (uf[u] < 0) ? u : (uf[u] = root(uf[u]));
}
bool connect(int u, int v) {
u = root(u);
v = root(v);
if (u == v) return false;
if (uf[u] > uf[v]) swap(u, v);
uf[u] += uf[v];
uf[v] = u;
return true;
}
constexpr int DX[4] = {+1, 0, -1, 0};
constexpr int DY[4] = {0, +1, 0, -1};
void experiment() {
for (int n = 2; n <= 5; ++n) {
vector<pair<Int, int>> qps;
for (int p = 1; p < 1 << (n*n); ++p) {
uf.assign(n*n, -1);
for (int x = 0; x < n; ++x) for (int y = 0; y < n; ++y) if (p >> (x*n+y) & 1) {
for (int dir = 0; dir < 4; ++dir) {
const int xx = x + DX[dir];
const int yy = y + DY[dir];
if (0 <= xx && xx < n && 0 <= yy && yy < n && (p >> (xx*n+yy) & 1)) {
connect(x*n+y, xx*n+yy);
}
}
}
if (-uf[root(__builtin_ctz(p))] == __builtin_popcount(p)) {
Int q = 0;
for (int x = 0; x < n; ++x) for (int y = 0; y < n; ++y) {
const int a = (p >> (x*n+y) & 1);
int cnt = 0;
for (int dir = 0; dir < 4; ++dir) {
const int xx = x + DX[dir];
const int yy = y + DY[dir];
const int aa = (0 <= xx && xx < n && 0 <= yy && yy < n) ? (p >> (xx*n+yy) & 1) : 0;
if (a != aa) {
++cnt;
}
}
(q *= 5) += cnt;
}
qps.emplace_back(q, p);
}
}
sort(qps.begin(), qps.end());
const int qpsLen = qps.size();
for (int i = 0, j; i < qpsLen; i = j) {
for (j = i; j < qpsLen && qps[i].first == qps[j].first; ++j) {}
if (j - i >= 2) {
for (int k = i; k < j; ++k) {
const int p = qps[k].second;
for (int x = 0; x < n; ++x) {
for (int y = 0; y < n; ++y) {
printf("%d", p >> (x*n+y) & 1);
}
puts("");
}
puts("");
}
puts("========");
puts("");
fflush(stdout);
}
}
}
}
/*
first solution:
11
10
01
11
========
001
111
100
011
010
110
========
0011
0010
1110
1000
0001
0111
0100
1100
========
00001
00111
00100
11100
10000
00011
00010
01110
01000
11000
========
*/
int N;
int a[4][30][30];
int main() {
// experiment();
for (; ~scanf("%d", &N); ) {
memset(a, 0, sizeof(a));
for (int z = 1; z <= N; ++z) {
a[0][z][z] = 1;
a[1][z][z] = 1;
if (z < N) {
if (z % 2 != 0) {
a[0][z + 1][z] = 1;
a[1][z][z + 1] = 1;
} else {
a[0][z][z + 1] = 1;
a[1][z + 1][z] = 1;
}
}
}
for (int h = 0; h < 2; ++h) {
for (int x = 1; x <= N; ++x) for (int y = 1; y <= N; ++y) {
for (int dir = 0; dir < 4; ++dir) {
if (a[h][x][y] != a[h][x + DX[dir]][y + DY[dir]]) {
++a[2 + h][x][y];
}
}
}
}
for (const int h : {2, 0, 1}) {
for (int x = 1; x <= N; ++x) {
for (int y = 1; y <= N; ++y) {
if (y > 1) printf(" ");
printf("%d", a[h][x][y]);
}
puts("");
}
puts("");
}
for (int x = 1; x <= N; ++x) for (int y = 1; y <= N; ++y) {
assert(a[2][x][y] == a[3][x][y]);
}
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3708kb
input:
5
output:
3 2 1 0 0 2 2 2 1 0 1 2 2 2 1 0 1 2 2 2 0 0 1 2 3 1 0 0 0 0 1 1 1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 1 1 1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 1 0 0 0 0 1 1
result:
ok ok
Test #2:
score: 0
Accepted
time: 1ms
memory: 3592kb
input:
2
output:
3 2 2 3 1 0 1 1 1 1 0 1
result:
ok ok
Test #3:
score: 0
Accepted
time: 1ms
memory: 3656kb
input:
3
output:
3 2 1 2 2 2 1 2 3 1 0 0 1 1 1 0 0 1 1 1 0 0 1 0 0 1 1
result:
ok ok
Test #4:
score: 0
Accepted
time: 1ms
memory: 3700kb
input:
4
output:
3 2 1 0 2 2 2 1 1 2 2 2 0 1 2 3 1 0 0 0 1 1 1 0 0 0 1 0 0 0 1 1 1 1 0 0 0 1 0 0 0 1 1 1 0 0 0 1
result:
ok ok
Test #5:
score: 0
Accepted
time: 1ms
memory: 3684kb
input:
10
output:
3 2 1 0 0 0 0 0 0 0 2 2 2 1 0 0 0 0 0 0 1 2 2 2 1 0 0 0 0 0 0 1 2 2 2 1 0 0 0 0 0 0 1 2 2 2 1 0 0 0 0 0 0 1 2 2 2 1 0 0 0 0 0 0 1 2 2 2 1 0 0 0 0 0 0 1 2 2 2 1 0 0 0 0 0 0 1 2 2 2 0 0 0 0 0 0 0 1 2 3 1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0...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