結果

問題 No.1324 Approximate the Matrix
ユーザー tailstails
提出日時 2020-12-21 01:08:12
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 906 bytes
コンパイル時間 866 ms
コンパイル使用メモリ 30,872 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 11:25:00
合計ジャッジ時間 2,198 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 1 ms
4,348 KB
testcase_29 AC 1 ms
4,348 KB
testcase_30 AC 1 ms
4,348 KB
testcase_31 AC 1 ms
4,348 KB
testcase_32 WA -
testcase_33 AC 1 ms
4,348 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 AC 5 ms
4,348 KB
testcase_43 AC 5 ms
4,348 KB
testcase_44 AC 5 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c:4:1: warning: return type defaults to 'int' [-Wimplicit-int]
    4 | main(){
      | ^~~~
main.c: In function 'main':
main.c:5:9: warning: implicit declaration of function 'scanf' [-Wimplicit-function-declaration]
    5 |         scanf("%d%d",&n,&k);
      |         ^~~~~
main.c:1:1: note: include '<stdio.h>' or provide a declaration of 'scanf'
  +++ |+#include <stdio.h>
    1 | int n,k,a[200],b[200];
main.c:5:9: warning: incompatible implicit declaration of built-in function 'scanf' [-Wbuiltin-declaration-mismatch]
    5 |         scanf("%d%d",&n,&k);
      |         ^~~~~
main.c:5:9: note: include '<stdio.h>' or provide a declaration of 'scanf'
main.c:56:9: warning: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
   56 |         printf("%ld",z);
      |         ^~~~~~
main.c:56:9: note: include '<stdio.h>' or provide a declaration of 'printf'
main.c:56:9: warning: incompatible implicit declaration of built-in function 'printf' [-Wbuiltin-declaration-mismatch]
main.c:56:9: note: include '<stdio.h>' or provide a declaration of 'printf'

ソースコード

diff #

int n,k,a[200],b[200];
int p[200][200];
int q[200][200];
main(){
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;++i){
		scanf("%d",&a[i]);
	}
	for(int j=0;j<n;++j){
		scanf("%d",&b[j]);
	}
	for(int i=0;i<n;++i){
		for(int j=0;j<n;++j){
			scanf("%d",&p[i][j]);
		}
	}
	for(int i=0;i<n;++i){
		while(a[i]){
			int v=-500,x=0;
			for(int j=0;j<n;++j){
				if(v<p[i][j]-q[i][j]){
					v=p[i][j]-q[i][j];
					x=j;
				}
			}
			++q[i][x];
			--b[x];
			--a[i];
		}
	}
	int j0=0;
	int j1=0;
	while(1){
		while(j0<n&&b[j0]>=0) ++j0;
		while(j1<n&&b[j1]<=0) ++j1;
		if(j0==n) break;
		int v=-500,x=0;
		for(int i=0;i<n;++i){
			if(q[i][j0]>0&&v<p[i][j1]-q[i][j1]-p[i][j0]+q[i][j0]){
				v=p[i][j1]-q[i][j1]-p[i][j0]+q[i][j0];
				x=i;
			}
		}
		--q[x][j0];
		++q[x][j1];
		++b[j0];
		--b[j1];
	}
	long z=0;
	for(int i=0;i<n;++i){
		for(int j=0;j<n;++j){
			long d=p[i][j]-q[i][j];
			z+=d*d;
		}
	}
	printf("%ld",z);
}
0