Submission #66063278


Source Code Expand

Copy
#include <stdio.h>
#include <inttypes.h>
int N, M;
int A[312345], B[312345];
int counts[1123456];
int main(void) {
int i;
uint64_t ans = 0;
if (scanf("%d%d", &N, &M) != 2) return 1;
for (i = 0; i < M; i++) {
if (scanf("%d%d", &A[i], &B[i]) != 2) return 1;
if (A[i] - 1 <= N + 1 - B[i]) {
counts[B[i] + (A[i] - 1)]++;
} else {
counts[A[i] - (N + 1 - B[i])]++;
}
}
counts[1] += counts[N + 1];
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include <stdio.h>
#include <inttypes.h>

int N, M;
int A[312345], B[312345];

int counts[1123456];

int main(void) {
	int i;
	uint64_t ans = 0;
	if (scanf("%d%d", &N, &M) != 2) return 1;
	for (i = 0; i < M; i++) {
		if (scanf("%d%d", &A[i], &B[i]) != 2) return 1;
		if (A[i] - 1 <= N + 1 - B[i]) {
			counts[B[i] + (A[i] - 1)]++;
		} else {
			counts[A[i] - (N + 1 - B[i])]++;
		}
	}
	counts[1] += counts[N + 1];
	for (i = 1; i <= N; i++) {
		if (counts[i] > 0) ans += (uint64_t)counts[i] * (M - counts[i]);
	}
	printf("%" PRIu64 "\n", ans / 2);
	return 0;
}

/*

対応する向きに隣の点に同じ数だけ移動 → 並行

点1を通るように正規化する → 反対側の点の番号が向きに対応する

*/

Submission Info

Submission Time
Task D - Line Crossing
User mikecat
Language C (gcc 12.2.0)
Score 400
Code Size 762 Byte
Status AC
Exec Time 61 ms
Memory 7840 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 2
AC × 34
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt
All 00_sample_00.txt, 00_sample_01.txt, 01_test_00.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt, 01_test_16.txt, 01_test_17.txt, 01_test_18.txt, 01_test_19.txt, 01_test_20.txt, 01_test_21.txt, 01_test_22.txt, 01_test_23.txt, 01_test_24.txt, 01_test_25.txt, 01_test_26.txt, 01_test_27.txt, 01_test_28.txt, 01_test_29.txt, 01_test_30.txt, 01_test_31.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 0 ms 1636 KB
00_sample_01.txt AC 1 ms 1632 KB
01_test_00.txt AC 1 ms 1644 KB
01_test_01.txt AC 7 ms 2068 KB
01_test_02.txt AC 1 ms 1624 KB
01_test_03.txt AC 8 ms 2248 KB
01_test_04.txt AC 1 ms 1576 KB
01_test_05.txt AC 15 ms 5436 KB
01_test_06.txt AC 60 ms 7608 KB
01_test_07.txt AC 49 ms 5216 KB
01_test_08.txt AC 1 ms 1944 KB
01_test_09.txt AC 10 ms 4096 KB
01_test_10.txt AC 58 ms 6812 KB
01_test_11.txt AC 18 ms 5328 KB
01_test_12.txt AC 2 ms 4572 KB
01_test_13.txt AC 55 ms 7624 KB
01_test_14.txt AC 61 ms 7840 KB
01_test_15.txt AC 29 ms 6672 KB
01_test_16.txt AC 2 ms 2532 KB
01_test_17.txt AC 50 ms 7568 KB
01_test_18.txt AC 17 ms 5172 KB
01_test_19.txt AC 16 ms 4048 KB
01_test_20.txt AC 24 ms 3544 KB
01_test_21.txt AC 33 ms 6752 KB
01_test_22.txt AC 28 ms 6628 KB
01_test_23.txt AC 24 ms 2864 KB
01_test_24.txt AC 3 ms 1736 KB
01_test_25.txt AC 28 ms 3080 KB
01_test_26.txt AC 5 ms 1760 KB
01_test_27.txt AC 31 ms 3352 KB
01_test_28.txt AC 0 ms 1712 KB
01_test_29.txt AC 0 ms 1744 KB
01_test_30.txt AC 0 ms 1568 KB
01_test_31.txt AC 26 ms 4056 KB


2025-05-24 (Sat)
00:15:41 +09:00