AtCoder Regular Contest 103

Submission #3487658

Source codeソースコード

#include <stdio.h>
#include <stdlib.h>

int main(void){
	int n, *v, v1[100001], v2[100001], max1, max2, max3, max4, i1, i2, count1=1, count2=1;
	scanf("%d", &n);
	v = (int *)malloc(sizeof(int)*n);
	for (int i = 0; i < n; ++i){
		scanf("%d", &v[i]);
	}
	for (int i = 0; i <= 100000; ++i){
		v1[i] = 0;
		v2[i] = 0;
	}

	for (int i = 0; i < n/2; ++i){
		v1[v[2*i]] += 1;
		v2[v[2*i+1]] += 1;
	}

	max1 = v1[1];
	max2 = v2[1];
	i1 = 1;
	i2 = 1;
	for (int i = 2; i <= 100000; ++i){
		if (max1 == v1[i]) {
			count1 +=1;
		}else if (max1 < v1[i]) {
			max1 = v1[i];
			i1 = i;
			count1 = 1;
		}
		if (max2 == v2[i]) {
			count2 +=1;
		}else if (max2 < v2[i]) {
			max2 = v2[i];
			i2 = i;
			count2 = 1;
		}
	}

	if ((i1!=i2) || (count1>1) || (count2>1)) {
		printf("%d\n", n-max1-max2);
	} else {
		v1[i1] = 0;
		v2[i2] = 0;
		max3 = v1[1];
		max4 = v2[1];

		i1 = 1;
		i2 = 1;
		for (int i = 2; i <= 100000; ++i){
			if (max3 < v1[i]) {
				max3 = v1[i];
				i1 = i;
			}
			if (max4 < v2[i]) {
				max4 = v2[i];
				i2 = i;
			}
		}
		if (max1+max4 >= max2+max3) {
			printf("%d\n", n-max1-max4);
		}else{
			printf("%d\n", n-max3-max2);
		}
	}
	return 0;
}

Submission

Task問題 C - /\/\/\/
User nameユーザ名 iver
Created time投稿日時
Language言語 C (GCC 5.4.1)
Status状態 AC
Score得点 300
Source lengthソースコード長 1224 Byte
File nameファイル名
Exec time実行時間 12 ms
Memory usageメモリ使用量 1280 KB

Compiler messageコンパイルメッセージ

./Main.c: In function ‘main’:
./Main.c:6:2: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
^
./Main.c:9:3: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &v[i]);
^

Test case

Set

Set name Score得点 / Max score Cases
Sample - sample1_3132.txt,sample2_iw.txt,sample3_1111.txt
All 300 / 300 ababa_0.txt,ababa_1.txt,eq_0.txt,eq_1.txt,rnd_17.txt,sample1_3132.txt,sample2_iw.txt,sample3_1111.txt,top2_0.txt,top2_1.txt,top2_2.txt,top2_3.txt,top2modoki_0.txt,top2modoki_1.txt,top2modoki_2.txt,top2modoki_3.txt,vary_1.txt,vary_2.txt,vary_3.txt,zoro_0.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
ababa_0.txt AC 12 ms 1280 KB
ababa_1.txt AC 12 ms 1280 KB
eq_0.txt AC 11 ms 1280 KB
eq_1.txt AC 11 ms 1280 KB
rnd_17.txt AC 11 ms 1280 KB
sample1_3132.txt AC 1 ms 896 KB
sample2_iw.txt AC 1 ms 896 KB
sample3_1111.txt AC 1 ms 896 KB
top2_0.txt AC 11 ms 1280 KB
top2_1.txt AC 11 ms 1280 KB
top2_2.txt AC 11 ms 1280 KB
top2_3.txt AC 11 ms 1280 KB
top2modoki_0.txt AC 11 ms 1280 KB
top2modoki_1.txt AC 12 ms 1280 KB
top2modoki_2.txt AC 11 ms 1280 KB
top2modoki_3.txt AC 11 ms 1280 KB
vary_1.txt AC 12 ms 1280 KB
vary_2.txt AC 12 ms 1280 KB
vary_3.txt AC 12 ms 1280 KB
zoro_0.txt AC 1 ms 896 KB