結果

問題 No.1708 Quality of Contest
ユーザー atjh16atjh16
提出日時 2021-10-17 11:48:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 344 ms / 2,000 ms
コード長 1,342 bytes
コンパイル時間 2,455 ms
コンパイル使用メモリ 215,152 KB
実行使用メモリ 20,492 KB
最終ジャッジ日時 2023-10-17 22:25:27
合計ジャッジ時間 9,107 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
10,720 KB
testcase_01 AC 4 ms
10,720 KB
testcase_02 AC 4 ms
10,724 KB
testcase_03 AC 9 ms
10,924 KB
testcase_04 AC 9 ms
10,948 KB
testcase_05 AC 9 ms
10,876 KB
testcase_06 AC 8 ms
10,856 KB
testcase_07 AC 8 ms
10,864 KB
testcase_08 AC 5 ms
10,672 KB
testcase_09 AC 292 ms
20,492 KB
testcase_10 AC 223 ms
12,712 KB
testcase_11 AC 306 ms
16,740 KB
testcase_12 AC 306 ms
17,732 KB
testcase_13 AC 278 ms
16,216 KB
testcase_14 AC 316 ms
17,796 KB
testcase_15 AC 340 ms
18,260 KB
testcase_16 AC 329 ms
18,980 KB
testcase_17 AC 299 ms
16,608 KB
testcase_18 AC 298 ms
16,960 KB
testcase_19 AC 306 ms
17,540 KB
testcase_20 AC 292 ms
16,548 KB
testcase_21 AC 334 ms
17,980 KB
testcase_22 AC 326 ms
17,556 KB
testcase_23 AC 344 ms
18,212 KB
testcase_24 AC 230 ms
13,624 KB
testcase_25 AC 231 ms
13,592 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/vector:64,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/functional:62,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/x86_64-pc-linux-gnu/bits/stdc++.h:71,
                 from main.cpp:1:
In member function 'void std::vector<_Tp, _Alloc>::pop_back() [with _Tp = long long int; _Alloc = std::allocator<long long int>]',
    inlined from 'int main()' at main.cpp:83:19:
/home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_vector.h:1320:9: warning: 'q2' may be used uninitialized [-Wmaybe-uninitialized]
 1320 |         --this->_M_impl._M_finish;
      |         ^~
main.cpp: In function 'int main()':
main.cpp:47:31: note: 'q2' was declared here
   47 |         int w = 1, y = 0, q1, q2;
      |                               ^~
In member function 'void std::vector<_Tp, _Alloc>::pop_back() [with _Tp = long long int; _Alloc = std::allocator<long long int>]',
    inlined from 'int main()' at main.cpp:70:19:
/home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_vector.h:1320:9: warning: 'q1' may be used uninitialized [-Wmaybe-uninitialized]
 1320 |         --this->_M_impl._M_finish;
      |         ^~
main.cpp: In function 'int main()':
main.cpp:47:27: note: 'q1' was declared here
   47 |         int w = 1, y = 0, q1, q2;
      |                           ^~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int n, k;
long long m, x, s, t, z = 0;
vector<long long> a[200000];
long long c[200000], d[200001];
priority_queue<pair<long long, int>> Q1, Q2;

int main()
{
	cin >> n >> m >> x;

	for (int i = 0; i < n; i++) {
		cin >> s >> t;
		t--;

		a[t].push_back(s);
	}

	for (int i = 0; i < m; i++) {
		if (a[i].size() > 0) {
			sort(a[i].begin(), a[i].end());
			Q2.push({ a[i].back(), i });
			a[i].pop_back();
		}
	}

	cin >> k;

	for (int i = 0; i < k; i++)
		cin >> c[i];

	sort(c, c + k);
	int j = 0, u = k;

	for (int i = 0; i < k; i++) {
		while (j <= c[i]) {
			d[j] = u;
			j++;
		}

		u--;
	}

	long long p1 = 0, p2 = 0, z1 = -1, z2 = -1;
	int w = 1, y = 0, q1, q2;

	while (w <= c[k - 1]) {
		if (!Q1.empty()) {
			p1 = Q1.top().first;
			q1 = Q1.top().second;
			Q1.pop();
			z1 = p1;
		}

		if (!Q2.empty()) {
			p2 = Q2.top().first;
			q2 = Q2.top().second;
			Q2.pop();
			z2 = p2 + x;
		}

		if (z1 >= z2) {
			z += z1 * d[w];
			z1 = 0;

			if (a[q1].size() > 0) {
				Q1.push({ a[q1].back(), q1 });
				a[q1].pop_back();
			}

			if(z2 > 0)
				Q2.push({ p2, q2 });
		}
		else {
			z += z2 * d[w];
			y++;
			z2 = 0;

			if (a[q2].size() > 0) {
				Q1.push({ a[q2].back(), q2 });
				a[q2].pop_back();
			}

			if(z1 > 0)
				Q1.push({ p1, q1 });
		}

		w++;
	}

	cout << z << endl;
}
0