답안 #308808

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
308808 2020-10-02T01:42:53 Z updown1 Automobil (COCI17_automobil) C++17
0 / 100
43 ms 32504 KB
/*
Code by @marlov       
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<long long,long long> pi;
 
#define maxV 1000002
#define MOD 1000000007
//const long long MOD=1000000007;
long long N,M,K;
long long sum=0;
set<long long> cols;
set<long long> rows;
long long cm[maxV];
long long rm[maxV];
 
long long qsum(long long T,long long s,long long e){
	T%=MOD;
	s%=MOD;
	e%=MOD;
	if(T%2==0) return ((T/2)*(s+e))%MOD;
	else return (((s+e)/2)*(T))%MOD;
}
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin>>N>>M>>K;
	fill(cm,cm+maxV,1);
	fill(rm,rm+maxV,1);
	char c;
	long long x,m;
	for(long long i=0;i<K;i++){
		cin>>c>>x>>m;
		x--;
		if(c=='R'){
			rows.insert(x);
			rm[x]*=m;
			rm[x]%=MOD;
		}else if(c=='S'){
			cols.insert(x);
			cm[x]*=m;
			cm[x]%=MOD;
		}
	}
	for(long long i=0;i<N;i++){
		sum+=rm[i]*(qsum(M,i*M+1,i*M+M));
		//sum+=MOD;
		sum%=MOD;
	}
	//cout<<"1st: "<<sum<<'\n';
	for(long long i:cols){
		//cout<<(qsum(N,i+1,(N-1)*M+i+1))<<'\n';
		sum+=(cm[i]-1)*(qsum(N,i+1,(N-1)*M+i+1));
		//sum+=MOD;
		sum%=MOD;
	}
	//cout<<"2nd: "<<sum<<'\n';
	for(long long i:cols){
		for(long long j:rows){
			long long cv=M*j+i+1;
			sum-=(cm[i]+rm[j]-1)*cv;
          assert(sum >= 0);
			//sum+=MOD;
			sum%=MOD;
			sum+=(cm[i]*rm[j])*cv;
			sum%=MOD;
		}
	}
	cout<<sum%MOD<<'\n';
    return 0;
}
 
/* stuff you should look for
	* long long overflow, array bounds
	* special cases (n=1,n=0?)
	* do smth instead of nothing and stay organized
*/
# 결과 실행 시간 메모리 Grader output
1 Runtime error 33 ms 32384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Runtime error 34 ms 32376 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Runtime error 31 ms 32248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Runtime error 31 ms 32376 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Runtime error 33 ms 32256 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Runtime error 32 ms 32248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Runtime error 33 ms 32376 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Runtime error 32 ms 32248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Runtime error 33 ms 32248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
10 Runtime error 32 ms 32248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
11 Runtime error 33 ms 32256 KB Execution killed with signal 11 (could be triggered by violating memory limits)
12 Runtime error 38 ms 32376 KB Execution killed with signal 11 (could be triggered by violating memory limits)
13 Runtime error 32 ms 32248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
14 Runtime error 39 ms 32248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
15 Runtime error 36 ms 32252 KB Execution killed with signal 11 (could be triggered by violating memory limits)
16 Runtime error 41 ms 32376 KB Execution killed with signal 11 (could be triggered by violating memory limits)
17 Runtime error 40 ms 32376 KB Execution killed with signal 11 (could be triggered by violating memory limits)
18 Runtime error 39 ms 32376 KB Execution killed with signal 11 (could be triggered by violating memory limits)
19 Runtime error 43 ms 32504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
20 Runtime error 41 ms 32384 KB Execution killed with signal 11 (could be triggered by violating memory limits)