Submission #1080662

# Submission time Handle Problem Language Result Execution time Memory
1080662 2024-08-29T12:04:57 Z alexander707070 Hexagonal Territory (APIO21_hexagon) C++14
0 / 100
876 ms 444 KB
#include<bits/stdc++.h>
#define MAXN 100007
#include "hexagon.h"

using namespace std;

const long long mod=1e9+7;

int n;

long long ff(long long x){
    long long a=x-1,b=x,c=x+1;

    if(a%3==0)a/=3;
    if(b%3==0)b/=3;
    if(c%3==0)c/=3;

    return (((a*b)%mod)*c)%mod;
}

long long ak,bk,d[MAXN],len[MAXN],xx,yy,ans;

long long calc(long long r1,long long r2,long long c1,long long c2){
    if(r1>r2)swap(r1,r2);

    /*if(r1%2==0 and r2%2==1){
        r1/=2; r2/=2;
        return (r2*(r2+1) - r1*(r1-1));
    }

    if(r1%2==0 and r2%2==0){
        r1/=2; r2/=2;
        return (r2*(r2+1) - r1*(r1-1) - r2);
    }

    if(r1%2==1 and r2%2==1){
        r1/=2; r2/=2;
        return (r2*(r2+1) - r1*(r1-1) - r1);
    }

    if(r1%2==1 and r2%2==0){
        r1/=2; r2/=2;
        return (r2*(r2+1) - r1*(r1-1) -r1 - r2);
    }*/

    long long res=0;
    for(long long s=r1;s<=r2;s++){
        res+=s/2;
    }

    return res;
}

int draw_territory(int N,int A,int B,vector<int> D,vector<int> L){
    n=N; ak=A; bk=B;

    for(int i=1;i<=n;i++){
        d[i]=D[i-1]; len[i]=L[i-1];
    }

    /*if(n==3){
        return ((ak*(((len[1]+1)*(len[1]+2)/2)%mod) )%mod + (bk*ff(len[1]+1))%mod)%mod ;
    }*/

    if(B==0){
        xx=5*mod; yy=5*mod;

        d[n+1]=d[1];

        for(int i=1;i<=n;i++){
            if(d[i]==1)xx+=2*len[i];
            if(d[i]==4)xx-=2*len[i];

            if(d[i]==2){
                if(d[i+1]!=2 and d[i+1]!=3)ans+=calc(xx,xx+len[i],yy,yy+len[i]);
                else ans+=calc(xx,xx+len[i]-1,yy,yy+len[i]-1);

                xx+=len[i]; yy+=len[i];
            }
            if(d[i]==3){
                if(d[i+1]!=2 and d[i+1]!=3)ans+=calc(xx,xx-len[i],yy,yy+len[i]);
                else ans+=calc(xx,xx-len[i]+1,yy,yy+len[i]-1);

                xx-=len[i]; yy+=len[i];
            }


            if(d[i]==6){
                if(d[i+1]!=6 and d[i+1]!=5)ans-=calc(xx-2,xx+len[i]-2,yy,yy-len[i]);
                else ans-=calc(xx-2,xx+len[i]-1-2,yy,yy-len[i]+1);

                xx+=len[i]; yy-=len[i];
            }
            if(d[i]==5){
                if(d[i+1]!=6 and d[i+1]!=5)ans-=calc(xx-2,xx-len[i]-2,yy,yy-len[i]);
                else ans-=calc(xx-2,xx-len[i]+1-2,yy,yy-len[i]+1);

                xx-=len[i]; yy-=len[i];
            }
        }

        if(ans<0){
            ans=0; d[0]=d[n];
            xx=5*mod; yy=5*mod;

            for(int i=n;i>=1;i--){
                if(d[i]==1)d[i]=4;
                else if(d[i]==4)d[i]=1;
                
                if(d[i]==2)d[i]=5;
                else if(d[i]==5)d[i]=2;

                if(d[i]==3)d[i]=6;
                else if(d[i]==6)d[i]=3;

                d[0]=d[n];

                if(d[i]==1)xx+=2*len[i];
                if(d[i]==4)xx-=2*len[i];

                if(d[i]==2){
                    if(d[i-1]!=2 and d[i-1]!=3)ans+=calc(xx,xx+len[i],yy,yy+len[i]);
                    else ans+=calc(xx,xx+len[i]-1,yy,yy+len[i]-1);

                    xx+=len[i]; yy+=len[i];
                }
                if(d[i]==3){
                    if(d[i-1]!=2 and d[i-1]!=3)ans+=calc(xx,xx-len[i],yy,yy+len[i]);
                    else ans+=calc(xx,xx-len[i]+1,yy,yy+len[i]-1);

                    xx-=len[i]; yy+=len[i];
                }


                if(d[i]==6){
                    if(d[i-1]!=6 and d[i-1]!=5)ans-=calc(xx-2,xx+len[i]-2,yy,yy-len[i]);
                    else ans-=calc(xx-2,xx+len[i]-1-2,yy,yy-len[i]+1);

                    xx+=len[i]; yy-=len[i];
                }
                if(d[i]==5){
                    if(d[i-1]!=6 and d[i-1]!=5)ans-=calc(xx-2,xx-len[i]-2,yy,yy-len[i]);
                    else ans-=calc(xx-2,xx-len[i]+1-2,yy,yy-len[i]+1);

                    xx-=len[i]; yy-=len[i];
                }
            }
        }

        return ans%mod;
    }
}

/*int main(){
    cout<<draw_territory(3,1,0,{3,1,5},{3,3,3})<<"\n";
}*/

Compilation message

hexagon.cpp: In function 'int draw_territory(int, int, int, std::vector<int>, std::vector<int>)':
hexagon.cpp:152:1: warning: control reaches end of non-void function [-Wreturn-type]
  152 | }
      | ^
# Verdict Execution time Memory Grader output
1 Incorrect 825 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 830 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 876 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 831 ms 424 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -