Submission #71387069
Source Code Expand
Copy
#include <stdio.h>#include <inttypes.h>int N;int a[312345];int main(void) {int i;int64_t ans = 0;int start = 0;if (scanf("%d", &N) != 1) return 1;for (i = 0; i < N; i++) {if (scanf("%d", &a[i]) != 1) return 1;}for (i = 1; i <= N; i++) { /* 最後の要素の次を番兵として用いる */if (a[start] != a[i]) {int nelems = i - start;ans += (int64_t)nelems * (nelems - 1) / 2;start = i;}}
#include <stdio.h>
#include <inttypes.h>
int N;
int a[312345];
int main(void) {
int i;
int64_t ans = 0;
int start = 0;
if (scanf("%d", &N) != 1) return 1;
for (i = 0; i < N; i++) {
if (scanf("%d", &a[i]) != 1) return 1;
}
for (i = 1; i <= N; i++) { /* 最後の要素の次を番兵として用いる */
if (a[start] != a[i]) {
int nelems = i - start;
ans += (int64_t)nelems * (nelems - 1) / 2;
start = i;
}
}
printf("%" PRId64 "\n", ans);
return 0;
}
/*
a_i <= a_j で a_i が a_j の倍数なのは、a_i = a_j のときのみ
*/
Submission Info
| Submission Time | |
|---|---|
| Task | A - 倍数ペア |
| User | mikecat |
| Language | C (gcc 12.2.0) |
| Score | 100 |
| Code Size | 592 Byte |
| Status | AC |
| Exec Time | 27 ms |
| Memory | 2904 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 100 / 100 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| 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_rnd_00.txt, 01_rnd_01.txt, 01_rnd_02.txt, 01_rnd_03.txt, 01_rnd_04.txt, 01_rnd_05.txt, 01_rnd_06.txt, 02_same_00.txt, 02_same_01.txt, 02_same_02.txt, 03_prime_00.txt, 03_prime_01.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00_sample_00.txt | AC | 0 ms | 1624 KiB |
| 00_sample_01.txt | AC | 0 ms | 1616 KiB |
| 00_sample_02.txt | AC | 0 ms | 1732 KiB |
| 01_rnd_00.txt | AC | 22 ms | 2592 KiB |
| 01_rnd_01.txt | AC | 4 ms | 1864 KiB |
| 01_rnd_02.txt | AC | 20 ms | 2584 KiB |
| 01_rnd_03.txt | AC | 10 ms | 2156 KiB |
| 01_rnd_04.txt | AC | 24 ms | 2800 KiB |
| 01_rnd_05.txt | AC | 26 ms | 2880 KiB |
| 01_rnd_06.txt | AC | 27 ms | 2804 KiB |
| 02_same_00.txt | AC | 0 ms | 1724 KiB |
| 02_same_01.txt | AC | 22 ms | 2884 KiB |
| 02_same_02.txt | AC | 20 ms | 2896 KiB |
| 03_prime_00.txt | AC | 23 ms | 2808 KiB |
| 03_prime_01.txt | AC | 24 ms | 2904 KiB |