# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
502592 | Habitus | Automobil (COCI17_automobil) | C++14 | 18 ms | 460 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define dec(x, y) fixed << setprecision((y)) << (x)
#define xx first
#define yy second
#define srt(v) sort((v).begin(), (v).end())
#define srtr(v) sort((v).rbegin(), (v).rend())
#define pb push_back
#define popb pop_back
#define sz(a) (int)(a).size()
#define len(a) (int)(a).length()
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll mod=(ll)1e9+7LL;
ll n, m;
int k;
map<ll, ll> rd, kl;
map<ll, bool> uzrd, uzkl;
ll suma;
int main() {
ios;
cin >> n >> m >> k;
for(int i=0; i<k; i++) {
char c; ll d, kol;
cin >> c >> d >> kol;
if(c=='R') {
if(!uzrd[d]) rd[d]=kol;
else rd[d]*=kol;
uzrd[d]=1;
}
else {
if(!uzkl[d]) kl[d]=kol;
else kl[d]*=kol;
uzkl[d]=1;
}
}
suma=(n*m+1LL)*(n*m)/2LL;
suma%=mod;
for(auto it=rd.begin(); it!=rd.end(); it++) {
ll d=it->first, kol=it->second;
if(uzrd[d]) {suma+=((d*m+1LL)*(d*m)/2LL-((d-1LL)*m+1LL)*((d-1LL)*m)/2LL)*(kol-1LL); suma%=mod;}
}
for(auto it=kl.begin(); it!=kl.end(); it++) {
ll d=it->first, kol=it->second;
if(uzkl[d]) {suma+=(n*(n-1LL)*m/2LL+d*n)*(kol-1LL); suma%=mod;}
}
//cout << suma;
for(auto it=rd.begin(); it!=rd.end(); it++) {
for(auto it1=kl.begin(); it1!=kl.end(); it1++) {
ll d=it->first, kol=it->second;
ll d1=it1->first, kol1=it1->second;
if(!uzrd[d] || !uzkl[d1]) continue;
suma-=(m*(d-1LL)+d1)*(kol+kol1-1LL);
suma+=(m*(d-1LL)+d1)*kol*kol1;
suma%=mod;
}
}
cout << suma;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |