답안 #720402

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
720402 2023-04-08T07:31:07 Z yellowtoad Automobil (COCI17_automobil) C++17
100 / 100
19 ms 15964 KB
#include <iostream>
#include <vector>
using namespace std;

const long long mod = 1000000007;
long long int n, m, k, x, y, sum = 0, b[2][1000010];
char ch;
vector<pair<long long,long long>> a[2]; // R = 0; S = 1;

int main() {
	cin >> n >> m >> k;
	for (int i = 1; i <= k; i++) {
		cin >> ch >> x >> y;
		for (int j = 0; j < a[ch%2].size(); j++) {
			if (a[ch%2][j].first == x) {
				a[ch%2][j].second *= y;
				a[ch%2][j].second %= mod;
				goto skip;
			}
		}
		a[ch%2].push_back({x,y});
		skip:;
	}
	for (int i = 1; i <= n; i++) b[0][i] = ((m*(i-1))+1+(m*(i-1))+m)*m/2;
	for (int i = 1; i <= m; i++) b[1][i] = (i+((n-1)*m)+i)*n/2;
	for (int i = 1; i <= n; i++) {
		sum += b[0][i];
		sum %= mod;
	}
	for (int i = 0; i < a[0].size(); i++) {
		sum += ((b[0][a[0][i].first]%mod)*((a[0][i].second-1)%mod)+mod)%mod;
		sum = (sum+mod)%mod;
	}
	for (int i = 0; i < a[1].size(); i++) {
		sum += ((b[1][a[1][i].first]%mod)*((a[1][i].second-1)%mod)+mod)%mod;
		sum = (sum+mod)%mod;
	}
	for (int i = 0; i < a[0].size(); i++) {
		for (int j = 0; j < a[1].size(); j++) {
			sum = (sum-((((a[0][i].first-1)*m+a[1][j].first)%mod)*(a[0][i].second%mod))%mod-((((a[0][i].first-1)*m+a[1][j].first)%mod)*(a[1][j].second%mod))%mod+((((a[0][i].first-1)*m+a[1][j].first)%mod)*((((a[1][j].second%mod)*(a[0][i].second%mod))+1)%mod))%mod)%mod;
			sum = (sum+mod)%mod;
		}
	}
	cout << (sum+mod)%mod << endl;
}

Compilation message

automobil.cpp: In function 'int main()':
automobil.cpp:14:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |   for (int j = 0; j < a[ch%2].size(); j++) {
      |                   ~~^~~~~~~~~~~~~~~~
automobil.cpp:30:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |  for (int i = 0; i < a[0].size(); i++) {
      |                  ~~^~~~~~~~~~~~~
automobil.cpp:34:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |  for (int i = 0; i < a[1].size(); i++) {
      |                  ~~^~~~~~~~~~~~~
automobil.cpp:38:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |  for (int i = 0; i < a[0].size(); i++) {
      |                  ~~^~~~~~~~~~~~~
automobil.cpp:39:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |   for (int j = 0; j < a[1].size(); j++) {
      |                   ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 ms 316 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 320 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 6 ms 2752 KB Output is correct
12 Correct 11 ms 8728 KB Output is correct
13 Correct 2 ms 828 KB Output is correct
14 Correct 9 ms 10096 KB Output is correct
15 Correct 10 ms 9028 KB Output is correct
16 Correct 15 ms 15964 KB Output is correct
17 Correct 15 ms 15884 KB Output is correct
18 Correct 17 ms 15956 KB Output is correct
19 Correct 19 ms 15928 KB Output is correct
20 Correct 15 ms 15940 KB Output is correct