Submission #85832

# Submission time Handle Problem Language Result Execution time Memory
85832 2018-11-21T21:19:55 Z kraljlavova1 Automobil (COCI17_automobil) C++11
100 / 100
57 ms 35556 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long int llint;
const int MAX=1000010,MOD=1e9+7;
int k,x,y;
int bio_r[MAX],bio_s[MAX];
char c;
llint n,m,sol,sums;
llint mr[MAX],ms[MAX];
llint sum_r[MAX],sum_s[MAX];
vector<pair<llint,llint> >vr,vs,vn;
int main(){
	for(int i=0;i<MAX;i++) mr[i]=1;
	for(int i=0;i<MAX;i++) ms[i]=1;
	cin>>n>>m>>k;
	sum_r[0]=(m*(m+1)/2)%MOD;
	for(int i=1;i<n;i++){
		llint mk=(m*m)%MOD;
		sum_r[i]=(sum_r[i-1]+mk)%MOD;
	}
	sum_s[0]=((n*(n-1)/2)*m+n)%MOD;
	for(int i=1;i<m;i++){
		sum_s[i]=(sum_s[i-1]+n)%MOD;
	}
	for(int i=0;i<k;i++){
		cin>>c>>x>>y;
		--x;
		if(c=='R'){
			bio_r[x]=1;
			mr[x]=(mr[x]*y)%MOD;
		}
		else{
			bio_s[x]=1;
			ms[x]=(ms[x]*y)%MOD;
		}
	}
	for(int i=0;i<MAX;i++){
		if(bio_r[i]){
			vr.push_back({i,mr[i]});
		}
		if(bio_s[i]){
			vs.push_back({i,ms[i]});
		}
	}
	for(int i=0;i<vs.size();i++){
		vn.push_back({vs[i].second-1,vs[i].first+1});
	}
	llint sum=0,dif=0;
	for(int i=0;i<vn.size();i++){
		sum=(sum+(vn[i].second*vn[i].first))%MOD;
		dif=(dif+m*vn[i].first)%MOD;
	}
	sum_r[0]=(sum_r[0]+sum)%MOD;
	sol=(sol+sum_r[0]*mr[0])%MOD;
	for(int i=1;i<n;i++){
		sum=(sum+dif)%MOD;
		sum_r[i]=(sum_r[i]+sum)%MOD;
		sol=(sol+sum_r[i]*mr[i])%MOD;
	}
	cout<<sol;
	return 0;
}

Compilation message

automobil.cpp: In function 'int main()':
automobil.cpp:45:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<vs.size();i++){
              ~^~~~~~~~~~
automobil.cpp:49:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<vn.size();i++){
              ~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 17 ms 15992 KB Output is correct
2 Correct 17 ms 16160 KB Output is correct
3 Correct 16 ms 16252 KB Output is correct
4 Correct 17 ms 16348 KB Output is correct
5 Correct 17 ms 16388 KB Output is correct
6 Correct 17 ms 16392 KB Output is correct
7 Correct 21 ms 16528 KB Output is correct
8 Correct 17 ms 16528 KB Output is correct
9 Correct 17 ms 16528 KB Output is correct
10 Correct 17 ms 16600 KB Output is correct
11 Correct 23 ms 19964 KB Output is correct
12 Correct 38 ms 27444 KB Output is correct
13 Correct 18 ms 27444 KB Output is correct
14 Correct 40 ms 27444 KB Output is correct
15 Correct 38 ms 27688 KB Output is correct
16 Correct 53 ms 35388 KB Output is correct
17 Correct 57 ms 35472 KB Output is correct
18 Correct 54 ms 35472 KB Output is correct
19 Correct 54 ms 35472 KB Output is correct
20 Correct 54 ms 35556 KB Output is correct