提出 #78123497
ソースコード 拡げる
Copy
#include <stdio.h>/* ちいぜん (小さいから全探索) *//* {1,2,3} -> ... -> {3,2,1} */int next_permutation(int arr[], int n) {int target;int i;int temp;for (i = n - 2; i >= 0; i--) {if (arr[i] < arr[i + 1]) break;}if (i < 0) return 0;target = i;for (i = 0; target + i + 1 < n - i - 1; i++) {temp = arr[target + 1 + i];arr[target + 1 + i] = arr[n - 1 - i];arr[n - i - 1] = temp;}
#include <stdio.h>
/* ちいぜん (小さいから全探索) */
/* {1,2,3} -> ... -> {3,2,1} */
int next_permutation(int arr[], int n) {
int target;
int i;
int temp;
for (i = n - 2; i >= 0; i--) {
if (arr[i] < arr[i + 1]) break;
}
if (i < 0) return 0;
target = i;
for (i = 0; target + i + 1 < n - i - 1; i++) {
temp = arr[target + 1 + i];
arr[target + 1 + i] = arr[n - 1 - i];
arr[n - i - 1] = temp;
}
for (i = target + 1; i < n; i++) {
if (arr[i] > arr[target]) break;
}
temp = arr[i];
arr[i] = arr[target];
arr[target] = temp;
return 1;
}
int main(void) {
int N;
int P[16];
int Q[16];
int i;
int ans = 0;
if (scanf("%d", &N) != 1) return 1;
for (i = 0; i < N; i++) {
if (scanf("%d", &P[i]) != 1) return 1;
}
for (i = 0; i < N; i++) {
if (scanf("%d", &Q[i]) != 1) return 1;
}
while (next_permutation(P, N)) {
int ok = 0;
for (i = 0; i < N; i++) {
if (P[i] < Q[i]) { ok = 1; break; }
if (P[i] > Q[i]) break;
}
if (!ok) break;
ans++;
}
printf("%d\n", ans);
return 0;
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | C - Between P and Q |
| ユーザ | mikecat |
| 言語 | C23 (GCC 14.2.0) |
| 得点 | 300 |
| コード長 | 1088 Byte |
| 結果 | AC |
| 実行時間 | 14 ms |
| メモリ | 1696 KiB |
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 300 / 300 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt |
| All | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 00_sample_00.txt | AC | 0 ms | 1624 KiB |
| 00_sample_01.txt | AC | 0 ms | 1696 KiB |
| 00_sample_02.txt | AC | 0 ms | 1644 KiB |
| 01_random_00.txt | AC | 14 ms | 1684 KiB |
| 01_random_01.txt | AC | 0 ms | 1624 KiB |
| 01_random_02.txt | AC | 0 ms | 1644 KiB |
| 01_random_03.txt | AC | 0 ms | 1596 KiB |
| 01_random_04.txt | AC | 0 ms | 1596 KiB |
| 01_random_05.txt | AC | 0 ms | 1552 KiB |
| 01_random_06.txt | AC | 6 ms | 1592 KiB |
| 01_random_07.txt | AC | 0 ms | 1636 KiB |
| 01_random_08.txt | AC | 6 ms | 1552 KiB |
| 01_random_09.txt | AC | 0 ms | 1552 KiB |
| 01_random_10.txt | AC | 2 ms | 1556 KiB |
| 01_random_11.txt | AC | 0 ms | 1644 KiB |
| 01_random_12.txt | AC | 8 ms | 1620 KiB |
| 01_random_13.txt | AC | 0 ms | 1564 KiB |
| 01_random_14.txt | AC | 6 ms | 1624 KiB |
| 01_random_15.txt | AC | 0 ms | 1564 KiB |