AtCoder Regular Contest 018

Submission #610232

Source codeソースコード

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

const long N=1000000;

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

long ab(long a){
	return(a>0)?a:-a;
}

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

	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=2*(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  ", x[t]);

				long center=lower_bound(sorted, sorted+n*m,x[t])-sorted;

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

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

				//printf("%ld (%ld,%ld)-> ",x[t], t/m, t%m);
				//printf("go to (%ld, %ld)\n",dest,seat[dest]);

				ans+=ab( dest - (t/m) ) + ab( 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状態 AC
Score得点 100
Source lengthソースコード長 1060 Byte
File nameファイル名
Exec time実行時間 32 ms
Memory usageメモリ使用量 1052 KB

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

./Main.cpp: In function ‘int main()’:
./Main.cpp:22:25: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
./Main.cpp:23: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 100 / 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 AC 27 ms 924 KB
case_02.txt AC 26 ms 872 KB
case_03.txt AC 26 ms 924 KB
case_04.txt AC 24 ms 868 KB
case_05.txt AC 24 ms 924 KB
case_06.txt AC 28 ms 852 KB
case_07.txt AC 25 ms 928 KB
case_08.txt AC 25 ms 924 KB
case_09.txt AC 28 ms 920 KB
case_10.txt AC 26 ms 924 KB
case_11.txt AC 24 ms 864 KB
case_12.txt AC 26 ms 924 KB
case_13.txt AC 25 ms 928 KB
case_14.txt AC 25 ms 924 KB
case_15.txt AC 27 ms 928 KB
case_16.txt AC 32 ms 924 KB
case_17.txt AC 27 ms 916 KB
case_18.txt AC 27 ms 860 KB
case_19.txt AC 27 ms 1048 KB
case_20.txt AC 26 ms 856 KB
case_21.txt AC 26 ms 920 KB
case_22.txt AC 26 ms 856 KB
case_23.txt AC 27 ms 924 KB
case_24.txt AC 27 ms 868 KB
case_25.txt AC 24 ms 924 KB
case_26.txt AC 26 ms 920 KB
case_27.txt AC 27 ms 868 KB
case_28.txt AC 25 ms 860 KB
case_29.txt AC 27 ms 920 KB
case_30.txt AC 28 ms 920 KB
case_31.txt AC 25 ms 928 KB
case_32.txt AC 26 ms 924 KB
case_33.txt AC 27 ms 904 KB
case_34.txt AC 26 ms 924 KB
case_35.txt AC 25 ms 920 KB
case_36.txt AC 26 ms 920 KB
case_37.txt AC 26 ms 872 KB
case_38.txt AC 26 ms 920 KB
case_39.txt AC 28 ms 860 KB
case_40.txt AC 26 ms 908 KB
case_41.txt AC 25 ms 868 KB
case_42.txt AC 24 ms 920 KB
case_43.txt AC 27 ms 868 KB
case_44.txt AC 24 ms 920 KB
case_45.txt AC 26 ms 924 KB
case_46.txt AC 27 ms 920 KB
case_47.txt AC 27 ms 924 KB
case_48.txt AC 26 ms 796 KB
case_49.txt AC 26 ms 868 KB
case_50.txt AC 28 ms 1052 KB
case_51.txt AC 28 ms 1048 KB
case_52.txt AC 26 ms 1048 KB
case_53.txt AC 31 ms 1020 KB
case_54.txt AC 28 ms 996 KB
case_55.txt AC 27 ms 1044 KB
case_56.txt AC 30 ms 996 KB
case_57.txt AC 28 ms 1000 KB
case_58.txt AC 30 ms 1044 KB
case_59.txt AC 26 ms 1048 KB
case_60.txt AC 28 ms 1044 KB
case_61.txt AC 28 ms 1052 KB
case_62.txt AC 26 ms 1044 KB
case_63.txt AC 28 ms 1048 KB
case_64.txt AC 28 ms 1052 KB
case_65.txt AC 26 ms 1048 KB
case_66.txt AC 26 ms 1044 KB
case_67.txt AC 28 ms 1052 KB
case_68.txt AC 28 ms 1052 KB
case_69.txt AC 28 ms 988 KB
case_70.txt AC 23 ms 916 KB
case_71.txt AC 24 ms 924 KB
case_72.txt AC 28 ms 928 KB
case_73.txt AC 26 ms 924 KB
case_74.txt AC 26 ms 868 KB
case_75.txt AC 26 ms 920 KB
case_76.txt AC 25 ms 920 KB
case_77.txt AC 26 ms 924 KB
case_78.txt AC 25 ms 920 KB
case_79.txt AC 25 ms 916 KB
sample_1.txt AC 24 ms 920 KB
sample_2.txt AC 23 ms 800 KB
sample_3.txt AC 25 ms 868 KB