結果
| 問題 | No.3765 321-avoiding Grid |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-10-16 22:02:29 |
| 言語 | C++23 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
WA
不安定
|
| 実行時間 | - |
| コード長 | 1,543 bytes |
| 記録 | |
| コンパイル時間 | 2,488 ms |
| コンパイル使用メモリ | 349,920 KB |
| 実行使用メモリ | 9,932 KB |
| 最終ジャッジ日時 | 2026-10-16 22:02:43 |
| 合計ジャッジ時間 | 8,677 ms |
|
ジャッジサーバーID (参考情報) |
judge5_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | AC * 5 WA * 3 RE * 20 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<pair<char, int>> a(3);
for(int i = 0; i < n; i++){
cin >> a[i].second;
a[i].first = '1' + i;
}
vector<string> A(n, string(n, '?'));
vector<pair<int,int>> dir = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
auto dfs = [&](auto dfs, int y, int x, int cur) -> bool {
if(cur == -1) return true;
for(auto [dy, dx] : dir){
int ny = y + dy, nx = x + dx;
if(ny < 0 || nx < 0 || ny >= n || nx >= n) continue;
if(A[ny][nx] == cur + '1' && dfs(dfs, ny, nx, cur - 1)) return true;
}
return false;
};
do{
auto b = a;
for(int y = 0; y < n; y++){
for(int x = 0; x < n; x++){
for(int i = 0; i < 3; i++){
if(b[i].second >= 1){
b[i].second--;
A[y][x] = b[i].first;
break;
}
}
}
}
bool flg = true;
for(int y = 0; y < n && flg; y++){
for(int x = 0; x < n; x++){
if(A[y][x] == '3' && dfs(dfs, y, x, 1)){
flg = false;
break;
}
}
}
if(flg){
for(auto &&str : A) cout << str << '\n';
return 0;
}
}while(next_permutation(a.begin(), a.end()));
}