結果

問題 No.628 Tagの勢い
ユーザー tonegawatonegawa
提出日時 2020-08-14 14:10:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 1,080 bytes
コンパイル時間 2,883 ms
コンパイル使用メモリ 207,328 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-18 18:34:14
合計ジャッジ時間 3,450 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define PI 3.14159265359
#define MAX 10000
#define NIL -1
using namespace std;
const int64_t MOD = 1e9 + 7;

int main() {
	int N, No, M, S;
	string Tag;
	cin >> N;

	struct info {
		string tag;
		int point;

		// 最後のconstを忘れると"instantiated from here"というエラーが出てコンパイルできないので注意
		bool operator<(const info& right) const {
			return point == right.point ? tag > right.tag : point < right.point;
		}
	};

	vector<struct info> v;
	for (int i = 0; i < N; i++) {
		cin >> No >> M >> S;

		for (int j = 0; j < M; j++) {
			cin >> Tag;

			int f = 0;
			for (int k = 0; k < v.size(); k++) {
				string t = v.at(k).tag;
				if (t == Tag) {
					v.at(k).point += S;
					f = 1;
				}
			}

			if (!f) {
				struct info inf = { Tag,S };
				v.push_back(inf);
			}
		}
	}
	sort(v.begin(), v.end());	//構造体の順序付けを定義しておく

	int n = v.size();
	int m = min(n, 10);
	//cout << n << endl;
	for (int i = 0; i < m; i++) {
		cout << v.at(n-1).tag << ' ' << v.at(n-1).point << endl;
		n--;
	}
}
0