結果

問題 No.1347 HS Railway
ユーザー 57tggx57tggx
提出日時 2021-03-05 14:44:13
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 113 ms / 2,000 ms
コード長 2,004 bytes
コンパイル時間 5,071 ms
コンパイル使用メモリ 258,524 KB
実行使用メモリ 8,728 KB
最終ジャッジ日時 2024-04-16 02:58:04
合計ジャッジ時間 9,841 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 3 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 45 ms
6,352 KB
testcase_13 AC 31 ms
5,376 KB
testcase_14 AC 17 ms
5,376 KB
testcase_15 AC 33 ms
6,912 KB
testcase_16 AC 55 ms
5,580 KB
testcase_17 AC 9 ms
5,376 KB
testcase_18 AC 77 ms
7,992 KB
testcase_19 AC 62 ms
5,376 KB
testcase_20 AC 74 ms
7,296 KB
testcase_21 AC 38 ms
6,144 KB
testcase_22 AC 88 ms
7,680 KB
testcase_23 AC 75 ms
5,752 KB
testcase_24 AC 31 ms
5,376 KB
testcase_25 AC 53 ms
5,732 KB
testcase_26 AC 79 ms
6,792 KB
testcase_27 AC 49 ms
7,424 KB
testcase_28 AC 96 ms
7,936 KB
testcase_29 AC 86 ms
7,296 KB
testcase_30 AC 76 ms
7,720 KB
testcase_31 AC 69 ms
7,868 KB
testcase_32 AC 92 ms
8,344 KB
testcase_33 AC 103 ms
8,348 KB
testcase_34 AC 99 ms
8,720 KB
testcase_35 AC 100 ms
8,728 KB
testcase_36 AC 99 ms
8,472 KB
testcase_37 AC 113 ms
8,476 KB
testcase_38 AC 106 ms
8,600 KB
testcase_39 AC 111 ms
8,476 KB
testcase_40 AC 90 ms
8,596 KB
testcase_41 AC 90 ms
8,344 KB
testcase_42 AC 93 ms
8,600 KB
testcase_43 AC 87 ms
8,344 KB
testcase_44 AC 83 ms
8,596 KB
testcase_45 AC 80 ms
8,600 KB
testcase_46 AC 92 ms
8,472 KB
testcase_47 AC 88 ms
8,340 KB
testcase_48 AC 103 ms
8,600 KB
testcase_49 AC 89 ms
8,476 KB
testcase_50 AC 98 ms
8,472 KB
testcase_51 AC 93 ms
8,344 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/extc++.h>

using lint = long long;

int main(){
	lint n;
	std::cin >> n;


	std::vector<lint> l(5), r(5);
	std::vector<std::vector<lint>> t(5, std::vector<lint>(n));
	for(lint i = 0; i < 5; ++i){
		std::cin >> l[i] >> r[i];
		--l[i];
		--r[i];
		for(lint j = l[i]; j < n - 1; ++j){
			lint a = 0;
			if(j < r[i]){
				std::cin >> a;
			}
			t[i][j + 1] = t[i][j] + a;
		}
	}

	/*
	for(lint i = 0; i < n; ++i){
		std::cout << std::setw(2) << i << " ";
	}
	std::cout << std::endl;
	for(lint i = 0; i < 5; ++i){
		for(lint j = 0; j < n; ++j){
			std::cout << std::setw(2) << t[i][j] << " ";
		}
		std::cout << std::endl;
	}
	*/

	lint m;
	std::cin >> m;

	std::vector<std::vector<lint>> s(5);
	for(lint i = 0; i < m; ++i){
		lint b, st;
		std::cin >> b >> st;
		--b;
		s[b].push_back(st);
	}
	for(lint i = 0; i < 5; ++i){
		std::sort(s[i].begin(), s[i].end());
	}

	/*
	for(lint i = 0; i < 5; ++i){
		for(lint j : s[i]){
			std::cout << j << " ";
		}
		std::cout << std::endl;
	}
	*/

	lint ans = 0;
	for(lint i = 0; i < 5; ++i){
		for(lint j = i + 1; j < 5; ++j){
			if(i == j) continue;
			lint from = std::max(l[i], l[j]);
			lint to = std::min(r[i], r[j]);
			if(from > to) continue;
			/*
			printf("%d %d\n", i, j);
			printf("t[%2d][%2d] = %2d\n", i, from, t[i][from]);
			printf("t[%2d][%2d] = %2d\n", j, from, t[j][from]);
			printf("t[%2d][%2d] = %2d\n", i, to, t[i][to]);
			printf("t[%2d][%2d] = %2d\n", j, to, t[j][to]);
			*/
			lint index1 = 0, index2 = 0;
			for(lint k : s[i]){
				while(index1 < s[j].size() && k + t[i][from] >= s[j][index1] + t[j][from]){
					// printf("%d + %d >= %d + %d\n", k, t[i][from], s[j][index1], t[j][from]);
					++index1;
				}
				while(index2 < s[j].size() && k + t[i][to] > s[j][index2] + t[j][to]){
					// printf("%d + %d > %d + %d\n", k, t[i][to], s[j][index2], t[j][to]);
					++index2;
				}
				// std::cout << k << " " << index1 << " " << index2 << std::endl;
				ans += index1 - index2;
			}
		}
	}
	std::cout << ans << std::endl;
}
0