QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#559092#8669. 正方形计数zhulexuan10 3848ms3736kbC++143.8kb2024-09-11 20:10:072024-09-11 20:10:07

Judging History

你现在查看的是最新测评结果

  • [2024-09-11 20:10:07]
  • 评测
  • 测评结果:10
  • 用时:3848ms
  • 内存:3736kb
  • [2024-09-11 20:10:07]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf INT_MAX
#define fr(i,l,r) for (i=(l); i<=(r); i++)
#define rfr(i,l,r) for (i=(l); i>=(r); i--)
template<typename T>inline void read(T &n){
    T w=1; n=0; char ch=getchar();
    while (!isdigit(ch) && ch!=EOF){ if (ch=='-') w=-1; ch=getchar(); }
    while (isdigit(ch) && ch!=EOF){ n=(n<<3)+(n<<1)+(ch&15); ch=getchar(); }
    n*=w;
}
template<typename T>inline void write(T x){
    if (x==0){ putchar('0'); return ; }
    T tmp;
    if (x>0) tmp=x;
    else tmp=-x;
    if (x<0) putchar('-');
    char F[105];
    long long cnt=0;
    while (tmp){
        F[++cnt]=tmp%10+48;
        tmp/=10;
    }
    while (cnt) putchar(F[cnt--]);
}
#define Min(x,y) x = min(x,y)
#define Max(x,y) x = max(x,y)
//基础配置=================================================================================
const ll N = 10, V = 2005;
ll n,m;
ll a[N],b[N];
// ll c[V][V];
ll lf[V],rh[V];
// ll d1[V][V],d2[V][V],d3[V][V],d4[V][V];//上,下,左,右
ll up_div(ll x,ll y){
    if (x%y==0) return x/y;
    else return x/y+1;
}
void make_map(){
    ll i,j,k;
    ll lm,rm;
    lm = inf; rm = 0;
    fr(i,1,n) Min(lm,a[i]), Max(rm,a[i]);
    // printf("lm = %lld , rm = %lld\n",lm,rm);
    fr(i,0,m)
        fr(j,0,m){
            if (i<lm || i>rm){ lf[i] = inf, rh[i] = -inf; }
            else lf[i] = 0, rh[i] = m;
        }
    fr(i,1,n){
        ll x = i, y = i%n+1;
        // printf("i = %lld , x = %lld , y = %lld\n",i,x,y);
        if (a[x]==a[y]){
            ll l = min(b[x],b[y]), r = max(b[x],b[y]);
            Min(rh[i],r);
            Max(lf[i],l);
            // fr(j,r+1,m) c[a[x]][j] = 0;
            // fr(j,0,l-1) c[a[x]][j] = 0;
            continue;
        }
        if (a[x]>a[y]){//下边界
            fr(j,a[y],a[x]){
                ll p = up_div( (j-a[y])*(b[x]-b[y]) + b[y]*(a[x]-a[y]) , a[x]-a[y] );
                // printf("%lld : 0 ~ %lld ban\n",j,p-1);
                Max(lf[j],p);
                // fr(k,0,p-1) c[j][k] = 0;
            }
        }
        else{//上边界
            fr(j,a[x],a[y]){
                ll p = up_div( (j-a[x])*(b[y]-b[x]) + b[x]*(a[y]-a[x]) , a[y]-a[x] );
                Min(rh[j],p);
                // fr(k,p+1,m) c[j][k] = 0;
                // printf("%lld : %lld ~ %lld ban\n",j,p+1,m);
            }
        }
    }
    // fr(i,0,m)
    //     fr(j,0,m)
    //         if (c[i][j]) printf("c[%lld][%lld] = %lld\n",i,j,c[i][j]);
}
int main(){
	// freopen("a.in","r",stdin);
//	freopen(".out","w",stdout);
    // double stt = clock();
    ll i,j,k;
    read(n); m = 2000;
    fr(i,1,n) read(a[i]), read(b[i]);
    make_map();
    // printf("0 : %lld ~ %lld\n",lf[0],rh[0]);
    // printf("1 : %lld ~ %lld\n",lf[1],rh[1]);
    // printf("2 : %lld ~ %lld\n",lf[2],rh[2]);
    ll ans = 0;
    ll lmx,rmx,lmy,rmy; lmx = lmy = inf, rmx = rmy = 0;
    fr(i,1,n)
        Min(lmx,a[i]),
        Min(lmy,b[i]),
        Max(rmx,a[i]),
        Max(rmy,b[i]);
    fr(i,0,rmx-lmx){//x轴长度
        fr(j,1,rmy-lmy){//y轴长度
            if (!i && !j) continue;
            // printf("\n\n\n\n solve %lld %lld\n",i,j);
            fr(k,lmx,rmx-i-j){//x轴所在位置
                // printf("\n k = %lld : ",k);
                ll l,r; l = 0, r = inf;
                Max(l,lf[k]); Max(l,lf[k+i]-j); Max(l,lf[k+i+j]-j+i); Max(l,lf[k+j]+i);
                Min(r,rh[k]); Min(r,rh[k+i]-j); Min(r,rh[k+i+j]-j+i); Min(r,rh[k+j]+i);
                // printf("%lld ~ %lld\n",l,r);
                if (l<=r) ans += r-l+1;
            }
        }
    }
    write(ans);
    // printf("\n\n Times : %.3fms\n",clock()-stt);
    return 0;
}
//g++ a.cpp -o a -Wall -Wl,--stack=512000000 -std=c++11 -O2

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 2631ms
memory: 3696kb

input:

4
131 603
131 1828
1919 1828
1919 603

output:

361182910200

result:

ok 1 number(s): "361182910200"

Test #2:

score: 10
Accepted
time: 3ms
memory: 3604kb

input:

4
239 211
239 962
261 962
261 211

output:

1498772

result:

ok 1 number(s): "1498772"

Test #3:

score: 10
Accepted
time: 3848ms
memory: 3608kb

input:

4
0 0
0 2000
2000 2000
2000 0

output:

1336001667000

result:

ok 1 number(s): "1336001667000"

Test #4:

score: 10
Accepted
time: 11ms
memory: 3564kb

input:

4
36 771
36 786
672 786
672 771

output:

427720

result:

ok 1 number(s): "427720"

Test #5:

score: 10
Accepted
time: 7ms
memory: 3736kb

input:

4
0 100
100 200
200 100
100 0

output:

34001650

result:

ok 1 number(s): "34001650"

Subtask #2:

score: 0
Wrong Answer

Test #6:

score: 0
Wrong Answer
time: 2551ms
memory: 3680kb

input:

3
131 603
131 1828
1919 603

output:

63947549768

result:

wrong answer 1st numbers differ - expected: '63739309181', found: '63947549768'

Subtask #3:

score: 0
Wrong Answer

Test #11:

score: 0
Wrong Answer
time: 3ms
memory: 3608kb

input:

8
0 13
4 15
15 15
15 6
13 1
12 0
5 0
0 6

output:

3366

result:

wrong answer 1st numbers differ - expected: '4047', found: '3366'

Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Skipped

Dependency #4:

0%

Subtask #6:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%