結果
| 問題 |
No.3092 Tired Queen
|
| コンテスト | |
| ユーザー |
Today03
|
| 提出日時 | 2025-04-06 17:16:22 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 86 ms / 2,000 ms |
| コード長 | 2,824 bytes |
| コンパイル時間 | 3,489 ms |
| コンパイル使用メモリ | 283,000 KB |
| 実行使用メモリ | 10,624 KB |
| 最終ジャッジ日時 | 2025-04-06 17:16:31 |
| 合計ジャッジ時間 | 7,823 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 41 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:89:23: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type’ {aka ‘long long int’} [-Wformat=]
89 | printf("%5d ", ans[i][j]);
| ~~^
| |
| int
| %5lld
ソースコード
#include <bits/stdc++.h>
#define ALL(x) (x).begin(), (x).end()
#define LB(v, x) (int)(lower_bound(ALL(v), x) - (v).begin())
#define UQ(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end())
#define IO ios::sync_with_stdio(false), cin.tie(nullptr);
#define chmax(a, b) (a) = (a) < (b) ? (b) : (a)
#define chmin(a, b) (a) = (a) < (b) ? (a) : (b)
using namespace std;
using ll = long long;
const int INF = 1e9 + 10;
const ll INFL = 4e18;
const vector<int> dx = {0, 1, 0, -1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
// 0下 1右 2上 3左 4右下 5右上 6左下 7左上
int main() {
ll N;
cin >> N;
vector<vector<ll>> ans(N, vector<ll>(N));
int x = 0, y = 0;
int type = 0;
if (N % 2 == 0) type = 1;
int idx = 1;
for (int t = N; t >= 1; t--) {
if (t % 2 == 1) {
vector<int> jun;
int gx, gy;
// 0下 1右 2上 3左 4右下 5右上 6左下 7左上
// 右下 上 左上 右
if (type == 0) jun = {4, 2, 7, 1}, gx = x + t - 1, gy = y;
// 左下 上 右上 左
else
jun = {6, 2, 5, 3}, gx = x - t + 1, gy = y;
int d = 0, d2 = t - 1;
while (true) {
ans[y][x] = idx++;
if (x == gx && y == gy) break;
if (d % 2 == 0)
x += dx[jun[d]] * d2, y += dy[jun[d]] * d2, d2--;
else
x += dx[jun[d]], y += dy[jun[d]];
d++, d %= 4;
}
if (type == 0)
x--, y++;
else
x++, y++;
} else {
vector<int> jun;
int px = x, py = y;
// 0下 1右 2上 3左 4右下 5右上 6左下 7左上
// 左上 右 右下 上
int shote;
if (type == 0) jun = {7, 1, 4, 2}, shote = 0;
// 左下 上 右上 左
else
jun = {6, 2, 5, 3}, shote = 1;
ans[y][x] = idx++;
x += dx[shote] * (t - 1);
y += dy[shote] * (t - 1);
int d = 0, d2 = t - 1;
while (true) {
if (x < 0 || x >= N || y < 0 || y >= N || ans[y][x] != 0) break;
ans[y][x] = idx++;
if (d % 2 == 0)
x += dx[jun[d]] * d2, y += dy[jun[d]] * d2, d2--;
else
x += dx[jun[d]], y += dy[jun[d]];
d++, d %= 4;
}
if (type == 0)
x = px - 1, y = py + 1;
else
x = px + 1, y = py + 1;
type = 1 - type;
}
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
printf("%5d ", ans[i][j]);
}
cout << endl;
}
}
Today03