結果
| 問題 | No.3765 321-avoiding Grid |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-10-16 21:43:47 |
| 言語 | C++23 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 4 ms / 1,000 ms |
| + 962µs | |
| コード長 | 2,689 bytes |
| 記録 | |
| コンパイル時間 | 2,425 ms |
| コンパイル使用メモリ | 346,656 KB |
| 実行使用メモリ | 9,796 KB |
| 最終ジャッジ日時 | 2026-10-16 21:43:59 |
| 合計ジャッジ時間 | 4,920 ms |
|
ジャッジサーバーID (参考情報) |
judge5_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 28 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
mt19937 mt;
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
int n, a, b, c;
cin >> n >> a >> b >> c;
if (n <= 3) {
vector<int> x;
rep(i, a) x.push_back(1);
rep(i, b) x.push_back(2);
rep(i, c) x.push_back(3);
while (true) {
shuffle(x.begin(), x.end(), mt);
vector<string> s(n);
rep(i, n * n) {
s[i % n].push_back(x[i] + '0');
}
int dx[4] = {0, 1, 0, -1};
int dy[4] = {-1, 0, 1, 0};
bool ok = true;
rep(i, n) rep(j, n) {
if (s[i][j] != '2')
continue;
vector<int> c(3, 0);
rep(k, 4) {
int nx = i + dx[k];
int ny = j + dy[k];
if (nx < 0 || ny < 0 || nx >= n || ny >= n)
continue;
c[s[nx][ny] - '1']++;
}
if (c[0] != 0 && c[2] != 0) {
ok = false;
}
}
if (ok) {
for (auto t : s)
cout << t << endl;
return 0;
}
}
}
if (a + c <= b) {
rep(i, n) {
rep(j, n) {
if (a) {
cout << '1';
a--;
} else if (b) {
cout << '2';
b--;
} else {
cout << '3';
c--;
}
}
cout << endl;
}
} else {
if (a < c) {
rep(i, n) {
rep(j, n) {
if (b) {
cout << '2';
b--;
} else if (c) {
cout << '3';
c--;
} else {
cout << '1';
a--;
}
}
cout << endl;
}
} else {
rep(i, n) {
rep(j, n) {
if (b) {
cout << '2';
b--;
} else if (a) {
cout << '1';
a--;
} else {
cout << '3';
c--;
}
}
cout << endl;
}
}
}
return 0;
}