AtCoder Regular Contest 018

Submission #610218

Source codeソースコード

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;

const long N=1000000;

long x[N+1];
long sorted[N+1];

int main(){
	int n, m;
	long a, p;
	long ans=0;
	int seat[1000];

	memset(seat, 0, sizeof(seat));

	scanf(" %d %d", &n ,&m);
	scanf(" %ld %ld %ld", &x[0], &a, &p);

	sorted[0]=x[0];
	for(long i=1; i<n*m; ++i){
		x[i]=(x[i-1]+a)%p;
		sorted[i]=x[i];
	}
	sort(sorted, sorted+n*m);

	//場合分け
	if(a%p==0){
		if(x[0]>x[1]) ans=n-1;
		else ans=0;
	}
	else{
		for(long i=0; i<m; ++i){
			for(long j=0; j<n; ++j){
				long t=j*m+i;
				//printf("looking :: %ld\n", x[t]);

				//2分探索
				long left=0, right=n*m-1;
				long center;
				while(left<right){
					center=(left+right)/2;
					if(sorted[center] < x[t]){
						left = center+1;
					}
					else if(sorted[center] > x[t]){
						right = center-1;
					}
					else break;
				}

				long dest=center/m; //行くべき列

				//printf("  dest=%ld\n", dest);

				ans+=fabs( dest - (t/m) ) + fabs( seat[dest] - (t%m) );
				seat[dest]++;
			}
		}

	}

	printf("%ld\n", ans);
}

Submission

Task問題 C - 席替え
User nameユーザ名 imulan
Created time投稿日時
Language言語 C++ (G++ 4.6.4)
Status状態 WA
Score得点 0
Source lengthソースコード長 1178 Byte
File nameファイル名
Exec time実行時間 ms
Memory usageメモリ使用量 -

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

./Main.cpp: In function ‘int main()’:
./Main.cpp:21:25: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
./Main.cpp:22:38: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]

Test case

Set

Set name Score得点 / Max score Cases
All 0 / 100 case_01.txt,case_02.txt,case_03.txt,case_04.txt,case_05.txt,case_06.txt,case_07.txt,case_08.txt,case_09.txt,case_10.txt,case_11.txt,case_12.txt,case_13.txt,case_14.txt,case_15.txt,case_16.txt,case_17.txt,case_18.txt,case_19.txt,case_20.txt,case_21.txt,case_22.txt,case_23.txt,case_24.txt,case_25.txt,case_26.txt,case_27.txt,case_28.txt,case_29.txt,case_30.txt,case_31.txt,case_32.txt,case_33.txt,case_34.txt,case_35.txt,case_36.txt,case_37.txt,case_38.txt,case_39.txt,case_40.txt,case_41.txt,case_42.txt,case_43.txt,case_44.txt,case_45.txt,case_46.txt,case_47.txt,case_48.txt,case_49.txt,case_50.txt,case_51.txt,case_52.txt,case_53.txt,case_54.txt,case_55.txt,case_56.txt,case_57.txt,case_58.txt,case_59.txt,case_60.txt,case_61.txt,case_62.txt,case_63.txt,case_64.txt,case_65.txt,case_66.txt,case_67.txt,case_68.txt,case_69.txt,case_70.txt,case_71.txt,case_72.txt,case_73.txt,case_74.txt,case_75.txt,case_76.txt,case_77.txt,case_78.txt,case_79.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
case_01.txt WA
case_02.txt WA
case_03.txt WA
case_04.txt WA
case_05.txt WA
case_06.txt WA
case_07.txt AC 31 ms 1376 KB
case_08.txt WA
case_09.txt WA
case_10.txt WA
case_11.txt WA
case_12.txt WA
case_13.txt AC 31 ms 1420 KB
case_14.txt WA
case_15.txt WA
case_16.txt WA
case_17.txt WA
case_18.txt WA
case_19.txt WA
case_20.txt WA
case_21.txt WA
case_22.txt WA
case_23.txt WA
case_24.txt WA
case_25.txt WA
case_26.txt AC 33 ms 1492 KB
case_27.txt WA
case_28.txt AC 32 ms 1328 KB
case_29.txt WA
case_30.txt WA
case_31.txt WA
case_32.txt WA
case_33.txt WA
case_34.txt WA
case_35.txt AC 30 ms 1436 KB
case_36.txt WA
case_37.txt WA
case_38.txt WA
case_39.txt WA
case_40.txt WA
case_41.txt AC 29 ms 1440 KB
case_42.txt WA
case_43.txt WA
case_44.txt WA
case_45.txt AC 31 ms 1428 KB
case_46.txt WA
case_47.txt WA
case_48.txt WA
case_49.txt AC 32 ms 1360 KB
case_50.txt WA
case_51.txt WA
case_52.txt WA
case_53.txt WA
case_54.txt WA
case_55.txt WA
case_56.txt WA
case_57.txt WA
case_58.txt WA
case_59.txt WA
case_60.txt WA
case_61.txt WA
case_62.txt WA
case_63.txt WA
case_64.txt WA
case_65.txt WA
case_66.txt WA
case_67.txt WA
case_68.txt WA
case_69.txt WA
case_70.txt AC 30 ms 1428 KB
case_71.txt WA
case_72.txt AC 32 ms 1372 KB
case_73.txt AC 32 ms 1488 KB
case_74.txt AC 31 ms 1356 KB
case_75.txt WA
case_76.txt AC 32 ms 1360 KB
case_77.txt WA
case_78.txt WA
case_79.txt WA
sample_1.txt AC 32 ms 1364 KB
sample_2.txt AC 32 ms 1364 KB
sample_3.txt AC 32 ms 1372 KB