提出 #41560507
ソースコード 拡げる
Copy
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;
- }
- 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 N, M;
- char S[16][16];
- int order[16];
- int main(void) {
- int i;
- if (scanf("%d%d", &N, &M) != 2) return 1;
- for (i = 0; i < N; i++) {
- if (scanf("%15s", S[i]) != 1) return 1;
- order[i] = i;
- }
- do {
- int ok = 1;
- int j;
- for (j = 1; j < N; j++) {
- int diff_count = 0;
- int k;
- for (k = 0; k < M; k++) {
- diff_count += S[order[j - 1]][k] != S[order[j]][k];
- }
- if (diff_count != 1) {
- ok = 0;
- break;
- }
- }
- if (ok) {
- puts("Yes");
- return 0;
- }
- } while (next_permutation(order, N));
- puts("No");
- return 0;
- }
#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 N, M;
char S[16][16];
int order[16];
int main(void) {
int i;
if (scanf("%d%d", &N, &M) != 2) return 1;
for (i = 0; i < N; i++) {
if (scanf("%15s", S[i]) != 1) return 1;
order[i] = i;
}
do {
int ok = 1;
int j;
for (j = 1; j < N; j++) {
int diff_count = 0;
int k;
for (k = 0; k < M; k++) {
diff_count += S[order[j - 1]][k] != S[order[j]][k];
}
if (diff_count != 1) {
ok = 0;
break;
}
}
if (ok) {
puts("Yes");
return 0;
}
} while (next_permutation(order, N));
puts("No");
return 0;
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | C - Almost Equal |
| ユーザ | mikecat |
| 言語 | C (GCC 9.2.1) |
| 得点 | 250 |
| コード長 | 1134 Byte |
| 結果 | AC |
| 実行時間 | 3 ms |
| メモリ | 1664 KB |
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 250 / 250 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | example_00.txt, example_01.txt, example_02.txt |
| All | example_00.txt, example_01.txt, example_02.txt, test_00.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt, test_11.txt, test_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt, test_19.txt, test_20.txt, test_21.txt, test_22.txt, test_23.txt, test_24.txt, test_25.txt, test_26.txt, test_27.txt, test_28.txt, test_29.txt, test_30.txt, test_31.txt, test_32.txt, test_33.txt, test_34.txt, test_35.txt, test_36.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| example_00.txt | AC | 3 ms | 1588 KB |
| example_01.txt | AC | 2 ms | 1604 KB |
| example_02.txt | AC | 2 ms | 1604 KB |
| test_00.txt | AC | 1 ms | 1608 KB |
| test_01.txt | AC | 1 ms | 1608 KB |
| test_02.txt | AC | 1 ms | 1640 KB |
| test_03.txt | AC | 1 ms | 1600 KB |
| test_04.txt | AC | 1 ms | 1592 KB |
| test_05.txt | AC | 1 ms | 1600 KB |
| test_06.txt | AC | 1 ms | 1564 KB |
| test_07.txt | AC | 1 ms | 1608 KB |
| test_08.txt | AC | 2 ms | 1512 KB |
| test_09.txt | AC | 2 ms | 1644 KB |
| test_10.txt | AC | 1 ms | 1584 KB |
| test_11.txt | AC | 2 ms | 1588 KB |
| test_12.txt | AC | 2 ms | 1600 KB |
| test_13.txt | AC | 1 ms | 1640 KB |
| test_14.txt | AC | 2 ms | 1604 KB |
| test_15.txt | AC | 2 ms | 1608 KB |
| test_16.txt | AC | 1 ms | 1604 KB |
| test_17.txt | AC | 1 ms | 1592 KB |
| test_18.txt | AC | 2 ms | 1608 KB |
| test_19.txt | AC | 1 ms | 1568 KB |
| test_20.txt | AC | 1 ms | 1580 KB |
| test_21.txt | AC | 2 ms | 1504 KB |
| test_22.txt | AC | 1 ms | 1664 KB |
| test_23.txt | AC | 2 ms | 1664 KB |
| test_24.txt | AC | 2 ms | 1504 KB |
| test_25.txt | AC | 2 ms | 1504 KB |
| test_26.txt | AC | 2 ms | 1516 KB |
| test_27.txt | AC | 2 ms | 1608 KB |
| test_28.txt | AC | 2 ms | 1604 KB |
| test_29.txt | AC | 2 ms | 1604 KB |
| test_30.txt | AC | 1 ms | 1660 KB |
| test_31.txt | AC | 1 ms | 1604 KB |
| test_32.txt | AC | 1 ms | 1592 KB |
| test_33.txt | AC | 1 ms | 1604 KB |
| test_34.txt | AC | 2 ms | 1656 KB |
| test_35.txt | AC | 1 ms | 1596 KB |
| test_36.txt | AC | 1 ms | 1568 KB |