結果

問題 No.1060 素敵な宝箱
ユーザー kotatsugamekotatsugame
提出日時 2020-05-22 22:04:54
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 841 bytes
コンパイル時間 1,042 ms
コンパイル使用メモリ 77,496 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-15 16:54:46
合計ジャッジ時間 1,971 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 3 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 9 ms
6,944 KB
testcase_13 AC 12 ms
6,940 KB
testcase_14 AC 14 ms
6,944 KB
testcase_15 AC 22 ms
6,944 KB
testcase_16 AC 17 ms
6,940 KB
testcase_17 AC 8 ms
6,940 KB
testcase_18 AC 11 ms
6,940 KB
testcase_19 AC 9 ms
6,940 KB
testcase_20 AC 19 ms
6,944 KB
testcase_21 AC 17 ms
6,940 KB
testcase_22 AC 18 ms
6,940 KB
testcase_23 AC 11 ms
6,940 KB
testcase_24 AC 27 ms
6,944 KB
testcase_25 AC 27 ms
6,940 KB
testcase_26 AC 28 ms
6,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:9:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    9 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int N,M;
int A[300][300];
long C[300],D[300];
bool vis[300];
main()
{
	cin>>N>>M;
	for(int i=0;i<N;i++)
	{
		for(int j=0;j<M;j++)
		{
			cin>>A[i][j];
			C[j]+=A[i][j];
		}
	}
	for(int _=1;_<N;_+=2)
	{
		long X=0;
		for(int j=0;j<M;j++)
		{
			X+=C[j]*C[j];
			X-=D[j]*D[j];
		}
		vector<pair<long,int> >Y;
		for(int i=0;i<N;i++)
		{
			if(vis[i])continue;
			long nX=0;
			for(int j=0;j<M;j++)
			{
				nX+=(C[j]-A[i][j])*(C[j]-A[i][j]);
				nX-=(D[j]+A[i][j])*(D[j]+A[i][j]);
			}
			Y.push_back(make_pair(nX-X,i));
		}
		sort(Y.begin(),Y.end());
		int id=Y[1].second;
		vis[Y[0].second]=true;
		vis[id]=true;
		for(int j=0;j<M;j++)
		{
			C[j]-=A[id][j];
			D[j]+=A[id][j];
		}
	}
	long ans=0;
	for(int j=0;j<M;j++)ans+=C[j]*C[j]-D[j]*D[j];
	cout<<ans<<endl;
}
0