Submission #755017

# Submission time Handle Problem Language Result Execution time Memory
755017 2023-06-09T09:57:44 Z bgnbvnbv Dominance (CEOI08_dominance) C++14
70 / 100
105 ms 47436 KB
#include<bits/stdc++.h>
#define TASKNAME "codeforce"
#define pb push_back
#define pli pair<int,int>
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
using ll=long long;
const ll maxN=3006;
const ll inf=1e18;
const ll mod=1e9+7;
short f[6005][6005];
void update(ll x1,ll x2,ll y1,ll y2,ll v)
{
    f[x1][y1]+=v;
    f[x2+1][y1]-=v;
    f[x1][y2+1]-=v;
    f[x2+1][y2+1]+=v;
}
ll w,h;
ll n,x[maxN],y[maxN],r[maxN];
char c[maxN];
vector<ll>vecc,vecr;
ll get(ll r1,ll l1,ll r2,ll l2)
{
    ll le,chan,le1,chan1;
    if((r2-l2+1)%2==0)
    {
        le=(r2-l2+1)/2;
        chan=(r2-l2+1)/2;
    }
    else
    {
        le=(r2-l2+1)/2;
        chan=(r2-l2+1)/2;
        if(r2%2==0)
        {
            chan++;
            //le--;
        }
        else le++;
    }
    swap(le,le1);
    swap(chan,chan1);
    swap(r1,r2);
    swap(l1,l2);
    if((r2-l2+1)%2==0)
    {
        le=(r2-l2+1)/2;
        chan=(r2-l2+1)/2;
    }
    else
    {
        le=(r2-l2+1)/2;
        chan=(r2-l2+1)/2;
        if(r2%2==0)
        {
            chan++;
            //le--;
        }
        else le++;
    }
    return (le*le1)+(chan*chan1);
}
void solve()
{
    cin >> w >> h;
    cin >> n;
    for(int i=1;i<=n;i++)
    {
        cin >> c[i] >> x[i] >> y[i] >> r[i];
        vecc.pb({x[i]-y[i]+r[i]});
        vecc.pb({x[i]-y[i]-r[i]});
        vecr.pb({x[i]+y[i]-r[i]});
        vecr.pb({x[i]+y[i]+r[i]});
    }
    sort(vecc.begin(),vecc.end());
    sort(vecr.begin(),vecr.end());
    vector<pli> cordr,cordc;
    cordc.pb({vecc[0],vecc[0]});
    for(int i=1;i<vecc.size();i++)
    {
        if(vecc[i]!=vecc[i-1])
        {
            if(vecc[i]-vecc[i-1]>=2)
            {
                cordc.pb({vecc[i-1]+1,vecc[i]-1});
            }
            cordc.pb({vecc[i],vecc[i]});
        }
    }
    cordr.pb({vecr[0],vecr[0]});
    for(int i=1;i<vecr.size();i++)
    {
        if(vecr[i]!=vecr[i-1])
        {
            if(vecr[i]-vecr[i-1]>=2)
            {
                cordr.pb({vecr[i-1]+1,vecr[i]-1});
            }
            cordr.pb({vecr[i],vecr[i]});
        }
    }
    for(int i=1;i<=n;i++)
    {
        ll l1=inf,r1=inf,l2=inf,r2=inf;
        for(int j=0;j<cordr.size();j++)
        {
            if(cordr[j].se>=x[i]+y[i]-r[i])
            {
                l1=min(l1,1ll*j);
            }
            if(cordr[j].se>=x[i]+y[i]+r[i])
            {
                r1=min(r1,1ll*j);
            }
        }
        for(int j=0;j<cordc.size();j++)
        {
            if(cordc[j].se>=x[i]-y[i]-r[i])
            {
                l2=min(l2,1ll*j);
            }
            if(cordc[j].se>=x[i]-y[i]+r[i])
            {
                r2=min(r2,1ll*j);
            }
        }
        if(c[i]=='W') update(l1,r1,l2,r2,1);
        else update(l1,r1,l2,r2,-1);
    }
    for(int i=1;i<cordr.size();i++)
    {
        for(int j=0;j<cordc.size();j++)
        {
            f[i][j]+=f[i-1][j];
        }
    }
    for(int i=0;i<cordr.size();i++)
    {
        for(int j=1;j<cordc.size();j++)
        {
            f[i][j]+=f[i][j-1];
        }
    }
    ll ans1=0,ans2=0;
    for(int i=0;i<cordr.size();i++)
    {
        for(int j=0;j<cordc.size();j++)
        {
            if(f[i][j]<0)
            {
                ans1+=get(cordr[i].se,cordr[i].fi,cordc[j].se,cordc[j].fi);
            }
            else if(f[i][j]>0)
            {
                ans2+=get(cordr[i].se,cordr[i].fi,cordc[j].se,cordc[j].fi);
            }
        }
    }
    cout << ans2<<' '<<ans1;
    // x=x+y
    // y=x-y

}
int main()
{
    fastio
    //freopen(TASKNAME".INP","r",stdin);
    //freopen(TASKNAME".OUT","w",stdout);
    solve();
}

Compilation message

dominance.cpp: In function 'void solve()':
dominance.cpp:82:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |     for(int i=1;i<vecc.size();i++)
      |                 ~^~~~~~~~~~~~
dominance.cpp:94:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 |     for(int i=1;i<vecr.size();i++)
      |                 ~^~~~~~~~~~~~
dominance.cpp:108:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  108 |         for(int j=0;j<cordr.size();j++)
      |                     ~^~~~~~~~~~~~~
dominance.cpp:119:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  119 |         for(int j=0;j<cordc.size();j++)
      |                     ~^~~~~~~~~~~~~
dominance.cpp:133:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  133 |     for(int i=1;i<cordr.size();i++)
      |                 ~^~~~~~~~~~~~~
dominance.cpp:135:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  135 |         for(int j=0;j<cordc.size();j++)
      |                     ~^~~~~~~~~~~~~
dominance.cpp:140:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  140 |     for(int i=0;i<cordr.size();i++)
      |                 ~^~~~~~~~~~~~~
dominance.cpp:142:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  142 |         for(int j=1;j<cordc.size();j++)
      |                     ~^~~~~~~~~~~~~
dominance.cpp:148:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  148 |     for(int i=0;i<cordr.size();i++)
      |                 ~^~~~~~~~~~~~~
dominance.cpp:150:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  150 |         for(int j=0;j<cordc.size();j++)
      |                     ~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 724 KB Output is correct
2 Correct 3 ms 2132 KB Output is correct
3 Correct 8 ms 5840 KB Output is correct
4 Runtime error 85 ms 35620 KB Memory limit exceeded
5 Runtime error 78 ms 41036 KB Memory limit exceeded
6 Correct 1 ms 1108 KB Output is correct
7 Correct 2 ms 1620 KB Output is correct
8 Correct 46 ms 22996 KB Output is correct
9 Runtime error 80 ms 33968 KB Memory limit exceeded
10 Runtime error 105 ms 40244 KB Memory limit exceeded
11 Runtime error 105 ms 43872 KB Memory limit exceeded
12 Correct 1 ms 468 KB Output is correct
13 Runtime error 94 ms 47436 KB Memory limit exceeded
14 Correct 1 ms 340 KB Output is correct
15 Correct 58 ms 19696 KB Output is correct
16 Correct 16 ms 10280 KB Output is correct
17 Correct 1 ms 1236 KB Output is correct
18 Correct 8 ms 4968 KB Output is correct
19 Correct 3 ms 2132 KB Output is correct
20 Correct 10 ms 5972 KB Output is correct