답안 #309219

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
309219 2020-10-02T22:29:04 Z Marlov Automobil (COCI17_automobil) C++14
0 / 100
1000 ms 16128 KB
/*
Code by @marlov       
*/
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <utility>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <iterator>
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;
}

void add(long long v){
	sum+=v;
	while(sum<0) sum+=MOD;
	sum%=MOD;
}
void sub(long long v){
	sum-=v;
	while(sum<0) sum+=MOD;
	sum%=MOD;
}
void mult(long long v){
	sum*=v;
	while(sum<0) sum+=MOD;
	sum%=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++){
		add(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';
		add((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;
			sub((cm[i]+rm[j]-1)*cv);
			//sum+=MOD;
			sum%=MOD;
			add((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 Execution timed out 1072 ms 16000 KB Time limit exceeded
2 Execution timed out 1092 ms 16000 KB Time limit exceeded
3 Execution timed out 1096 ms 16000 KB Time limit exceeded
4 Execution timed out 1091 ms 16000 KB Time limit exceeded
5 Execution timed out 1090 ms 16000 KB Time limit exceeded
6 Execution timed out 1096 ms 16000 KB Time limit exceeded
7 Execution timed out 1091 ms 16000 KB Time limit exceeded
8 Execution timed out 1091 ms 16000 KB Time limit exceeded
9 Execution timed out 1095 ms 16000 KB Time limit exceeded
10 Execution timed out 1096 ms 16000 KB Time limit exceeded
11 Execution timed out 1091 ms 16000 KB Time limit exceeded
12 Execution timed out 1092 ms 16128 KB Time limit exceeded
13 Execution timed out 1086 ms 16000 KB Time limit exceeded
14 Execution timed out 1071 ms 16000 KB Time limit exceeded
15 Execution timed out 1088 ms 16000 KB Time limit exceeded
16 Execution timed out 1095 ms 16000 KB Time limit exceeded
17 Execution timed out 1047 ms 16000 KB Time limit exceeded
18 Execution timed out 1092 ms 16000 KB Time limit exceeded
19 Execution timed out 1094 ms 16000 KB Time limit exceeded
20 Execution timed out 1093 ms 16000 KB Time limit exceeded