結果
| 問題 |
No.3092 Tired Queen
|
| コンテスト | |
| ユーザー |
pengin_2000
|
| 提出日時 | 2025-04-06 16:32:39 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 78 ms / 2,000 ms |
| コード長 | 2,740 bytes |
| コンパイル時間 | 1,344 ms |
| コンパイル使用メモリ | 27,136 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2025-04-06 16:32:45 |
| 合計ジャッジ時間 | 5,312 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 41 |
コンパイルメッセージ
main.c: In function ‘main’:
main.c:6:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
6 | scanf("%d", &n);
| ^~~~~~~~~~~~~~~
ソースコード
#include<stdio.h>
int a[1003][1003];
int main()
{
int n;
scanf("%d", &n);
int i, j, k;
for (i = 0; i < n; i++)
for (j = 0; j < n; j++)
a[i][j] = -1;
int next;
if (n % 2 > 0)
{
a[0][0] = 1;
next = 2;
for (k = 1; k < n - 1; k += 2)
{
a[k][k - 1] = next;
next++;
i = k;
j = k - 1;
for (;;)
{
if (next % 2 == 0)
{
if (i == k)
{
if (a[i + 1][j] < 0)
{
i++;
a[i][j] = next;
next++;
}
else
{
j--;
a[i][j] = next;
next++;
}
}
else if (j == k)
{
if (a[i][j + 1] < 0)
{
j++;
a[i][j] = next;
next++;
}
else
{
i--;
a[i][j] = next;
next++;
}
}
else if (i == k + 1)
{
if (a[i - 1][j] < 0)
{
i--;
a[i][j] = next;
next++;
}
else if (j > 0)
{
j--;
a[i][j] = next;
next++;
}
else
break;
}
else
{
if (a[i][j - 1] < 0)
{
j--;
a[i][j] = next;
next++;
}
else
{
i--;
a[i][j] = next;
next++;
}
}
}
else
{
i ^= j;
j ^= i;
i ^= j;
a[i][j] = next;
next++;
}
}
a[k + 1][k] = next;
next++;
a[k][k + 1] = next;
next++;
a[k][k] = next;
next++;
a[k + 1][k + 1] = next;
next++;
}
}
else
{
a[0][0] = 1;
a[1][0] = 2;
a[0][1] = 3;
a[1][1] = 4;
next = 5;
for (k = 2; k < n - 1; k++)
{
a[k][k] = next;
next++;
i = j = k;
for (;;)
{
if (i == k)
{
if (a[j][i] < 0)
{
i ^= j;
j ^= i;
i ^= j;
a[i][j] = next;
next++;
}
else if (j > 0)
{
j--;
a[i][j] = next;
next++;
}
else
break;
}
else
{
if (a[j][i] < 0)
{
i ^= j;
j ^= i;
i ^= j;
a[i][j] = next;
next++;
}
else
{
i--;
a[i][j] = next;
next++;
}
}
}
i++;
a[i][j] = next;
next++;
k++;
for (;;)
{
if (i == k)
{
if (a[j][i] < 0)
{
i ^= j;
j ^= i;
i ^= j;
a[i][j] = next;
next++;
}
else if (j < k)
{
j++;
a[i][j] = next;
next++;
}
else
break;
}
else
{
if (a[j][i] < 0)
{
i ^= j;
j ^= i;
i ^= j;
a[i][j] = next;
next++;
}
else
{
i++;
a[i][j] = next;
next++;
}
}
}
}
}
for (i = 0; i < n; i++)
{
for (j = 0; j < n - 1; j++)
printf("%d ", a[i][j]);
printf("%d\n", a[i][j]);
}
return 0;
}
pengin_2000