結果

問題 No.335 門松宝くじ
ユーザー kurenai3110kurenai3110
提出日時 2016-12-20 18:22:22
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,993 bytes
コンパイル時間 1,064 ms
コンパイル使用メモリ 91,064 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-08 08:48:40
合計ジャッジ時間 7,129 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 1 ms
5,248 KB
testcase_03 AC 1 ms
5,248 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 555 ms
5,376 KB
testcase_08 AC 155 ms
5,376 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
#include <cmath>
using namespace std;

bool used[801][801];

int main() {
	int n, m; cin >> n >> m;
	vector<vector<int>>E(m);
	for (int i = 0; i < m; i++){
		E[i].resize(n);
		for (int j = 0; j < n; j++){
			cin >> E[i][j];
		}
	}

	vector<pair<long long, int>>A;
	for (int i = 0; i < m; i++){
		for (int s = 0; s < n; s++)for (int t = 0; t < n; t++)used[s][t] = 0;
		int maxE = n;
		long long sum = 0;
		while (E[i].size()){
			bool right = false;
			int Ej = 0;
			vector<pair<int, int>>L, R;
			for (int j = 0; j < E[i].size(); j++){
				if (E[i][j] == maxE){
					Ej = j;
					right = true;
					E[i].erase(E[i].begin() + j);
					j--;
					continue;
				}
				if (right)R.push_back(make_pair(E[i][j], j - Ej));
				else L.push_back(make_pair(E[i][j], j));
			}

			sort(L.begin(), L.end());
			sort(R.begin(), R.end());
			int cnt = 0;
			for (int j = 0; j < L.size(); j++){
				for (int k = j + 1; k < L.size(); k++){
					if (L[k].second < L[j].second){
						if (!used[L[j].first][L[k].first])used[L[j].first][L[k].first] = true, cnt++;
						if (!used[L[j].first][maxE])used[L[j].first][maxE] = true, cnt++;
						if (!used[L[k].first][maxE])used[L[k].first][maxE] = true, cnt++;
					}
				}
			}
			for (int j = 0; j < R.size(); j++){
				for (int k = j + 1; k < R.size(); k++){
					if (R[k].second > R[j].second){
						if (!used[R[j].first][R[k].first])used[R[j].first][R[k].first] = true, cnt++;
						if (!used[R[j].first][maxE])used[R[j].first][maxE] = true, cnt++;
						if (!used[R[k].first][maxE])used[R[k].first][maxE] = true, cnt++;
					}
				}
			}


			for (int j = 0; j < R.size(); j++)for (int k = 0; k < L.size(); k++){
				if (!used[L[k].first][R[j].first])used[L[k].first][R[j].first] = true, cnt++;
			}
			sum += cnt*maxE;

			maxE--;
		}
		A.push_back(make_pair((long long)1e9 - sum, i));
	}
	sort(A.begin(), A.end());

	cout << A[0].second << endl;

	return 0;
}
0