QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#818370 | #9884. Grid Construction | ucup-team004 | RE | 0ms | 4112kb | C++23 | 5.1kb | 2024-12-17 19:30:59 | 2024-12-17 19:31:08 |
Judging History
answer
#include <bits/stdc++.h>
using i64 = long long;
using u64 = unsigned long long;
using u32 = unsigned;
using u128 = unsigned __int128;
struct DSU {
std::vector<int> f, siz;
DSU() {}
DSU(int n) {
init(n);
}
void init(int n) {
f.resize(n);
std::iota(f.begin(), f.end(), 0);
siz.assign(n, 1);
}
int find(int x) {
while (x != f[x]) {
x = f[x] = f[f[x]];
}
return x;
}
bool same(int x, int y) {
return find(x) == find(y);
}
bool merge(int x, int y) {
x = find(x);
y = find(y);
if (x == y) {
return false;
}
siz[x] += siz[y];
f[y] = x;
return true;
}
int size(int x) {
return siz[find(x)];
}
};
std::vector<std::string> construct(int H, int W) {
std::vector s(H, std::string(W, '.'));
if (H > W) {
auto s1 = construct(W, H);
if (s1.empty()) {
return {};
}
for (int i = 0; i < W; i++) {
for (int j = 0; j < W; j++) {
char c = s1[i][j];
if (c == '<') {
c = '^';
} else if (c == '^') {
c = '<';
} else if (c == '>') {
c = 'v';
} else if (c == 'v') {
c = '>';
}
s[j] += c;
}
}
return s;
}
if (H == 2 && W == 2) {
s[0] = "<^";
s[1] = "v>";
return s;
}
if (H % 2 == 0 || W % 2 == 0) {
return {};
}
if (H % 3 == 1 || W % 3 == 1) {
return {};
}
if (H % 6 != W % 6) {
return {};
}
if (H == 3 && W == 3) {
s[0] = "<<^";
s[1] = "v.^";
s[2] = "v>>";
return s;
}
if (H == 5 && W == 5) {
s[0] = "<<<<^";
s[1] = "v.v.^";
s[2] = "v>.<^";
s[3] = "v.^.^";
s[4] = "v>>>>";
return s;
}
if (H < 5) {
return {};
}
int x = 0, y = 0;
while (H > 11) {
for (int i = 0; i < W - 1; i++) {
s[x][y + i] = '<';
}
for (int i = 0; i < H - 1; i++) {
s[x + i][y + W - 1] = '^';
}
for (int i = W - 1; i > 0; i--) {
s[x + H - 1][y + i] = '>';
}
for (int i = H - 1; i > 0; i--) {
s[x + i][y] = 'v';
}
x++;
y++;
H -= 2;
W -= 2;
for (int i = 1; i < W; i += 2) {
s[x][y + i] = 'v';
s[x + H - 1][y + i] = '^';
}
for (int i = 1; i < H; i += 2) {
s[x + i][y] = '>';
s[x + i][y + W - 1] = '<';
}
x++;
y++;
H -= 2;
W -= 2;
for (int i = 1; i < W; i += 2) {
s[x][y + i] = '^';
s[x + H - 1][y + i] = 'v';
}
for (int i = 1; i < H; i += 2) {
s[x + i][y] = '<';
s[x + i][y + W - 1] = '>';
}
x++;
y++;
H -= 2;
W -= 2;
}
for (int i = 0; i < W - 1; i++) {
s[x][y + i] = '<';
}
for (int i = 0; i < H - 1; i++) {
s[x + i][y + W - 1] = '^';
}
for (int i = W - 1; i > 0; i--) {
s[x + H - 1][y + i] = '>';
}
for (int i = H - 1; i > 0; i--) {
s[x + i][y] = 'v';
}
x++;
y++;
H -= 2;
W -= 2;
for (int i = 1; i < W; i += 2) {
s[x][y + i] = 'v';
s[x + H - 1][y + i] = '^';
}
for (int i = 1; i < H; i += 2) {
s[x + i][y] = '>';
s[x + i][y + W - 1] = '<';
}
x++;
y++;
H -= 2;
W -= 2;
if (H == 5) {
for (int i = 0; i < W; i++) {
s[x][y + i] = ".<v>.^"[i % 6];
s[x + 1][y + i] = i < W - 1 ? "^.v.<<"[i % 6] : '^';
s[x + 2][y + i] = i < 2 ? '>' : i >= W - 2 ? '<' : "^>.<v."[i % 6];
s[x + 3][y + i] = i == 0 ? 'v' : ">.^.v>"[i % 6];
s[x + 4][y + i] = ".<^>.v"[i % 6];
}
} else {
for (int i = 0; i < W; i++) {
s[x][y + i] = i < W - 4 ? ".^.<v>"[i % 6] : ".^" [i % 2];
s[x + 1][y + i] = i < W - 4 ? "<^>.v."[i % 6] : '>';
s[x + 2][y + i] = i < W - 4 ? ".^.<v>"[i % 6] : ".v" [i % 2];
s[x + 3][y + i] = i < W - 4 ? "<^>.v."[i % 6] : ".<v>"[i - W + 4];
s[x + 4][y + i] = i == W - 2 ? 'v' : ".^"[i % 2];
s[x + 5][y + i] = i == W - 2 ? 'v' : i == W - 1 ? '>' : '<';
s[x + 6][y + i] = ".v"[i % 2];
}
}
return s;
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int H, W;
std::cin >> H >> W;
auto ans = construct(H, W);
if (ans.empty()) {
std::cout << "No\n";
return 0;
}
std::cout << "Yes\n";
for (int i = 0; i < H; i++) {
std::cout << ans[i] << "\n";
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3756kb
input:
3 3
output:
Yes <<^ v.^ v>>
result:
ok Correct
Test #2:
score: 0
Accepted
time: 0ms
memory: 3528kb
input:
4 4
output:
No
result:
ok Correct : No
Test #3:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
4 5
output:
No
result:
ok Correct : No
Test #4:
score: 0
Accepted
time: 0ms
memory: 3544kb
input:
11 17
output:
Yes <<<<<<<<<<<<<<<<^ v.v.v.v.v.v.v.v.^ v>.^.<v>.^.^.^.<^ v.<^>.v.<^>>>>>.^ v>.^.<v>.^.v.v.<^ v.<^>.v.<^>.<v>.^ v>.^.^.^.^.^.v.<^ v.<<<<<<<<<<<v>.^ v>.v.v.v.v.v.v.<^ v.^.^.^.^.^.^.^.^ v>>>>>>>>>>>>>>>>
result:
ok Correct
Test #5:
score: 0
Accepted
time: 0ms
memory: 4112kb
input:
1000 1000
output:
No
result:
ok Correct : No
Test #6:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
6 6
output:
No
result:
ok Correct : No
Test #7:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
7 7
output:
No
result:
ok Correct : No
Test #8:
score: 0
Accepted
time: 0ms
memory: 3828kb
input:
8 8
output:
No
result:
ok Correct : No
Test #9:
score: 0
Accepted
time: 0ms
memory: 3488kb
input:
9 9
output:
Yes <<<<<<<<^ v.v.v.v.^ v>.<v>.<^ v.^.v.^.^ v>>>.<<<^ v.v.^.v.^ v>.<^>.<^ v.^.^.^.^ v>>>>>>>>
result:
ok Correct
Test #10:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
3 9
output:
No
result:
ok Correct : No
Test #11:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
15 3
output:
No
result:
ok Correct : No
Test #12:
score: -100
Runtime Error
input:
5 11