Submission #1104049

# Submission time Handle Problem Language Result Execution time Memory
1104049 2024-10-22T15:50:29 Z PedroBigMan Mosaic (IOI24_mosaic) C++17
100 / 100
185 ms 47284 KB
#include "mosaic.h"
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <list>
#include <iomanip>
#include <stdlib.h>
#include <time.h>
#include <cstring>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define REP(i,a,b) for(ll i=(ll) a; i<(ll) b; i++)
#define pb push_back
#define mp make_pair
#define pl pair<ll,ll>
#define ff first
#define ss second
#define whole(x) x.begin(),x.end()
#define DEBUG(i) cout<<"Pedro "<<i<<endl
#define INF 1000000000000000000LL
#define EPS ((ld)0.00000000001)
#define pi ((ld)3.141592653589793)
#define VV(vvvv,NNNN,xxxx); REP(iiiii,0,NNNN) {vvvv.pb(xxxx);}
ll mod=1000000007;

template<class A=ll> 
void Out(vector<A> a) {REP(i,0,a.size()) {cout<<a[i]<<" ";} cout<<endl;}

template<class A=ll>
void In(vector<A> &a, ll N) {A cur; REP(i,0,N) {cin>>cur; a.pb(cur);}} 

vector<vector<ll> > ps_small_up, ps_small_left, ps_small;
ll X, Y;
vector<ll> psX, psY, psX_temp, psY_temp;

ll f(ll A, ll B)
{
    if(A==0 && B==0) {return 1;} else {return 0;}
}

ll PS(ll x1, ll x2, ll y1, ll y2)
{
    if(x1==0 && y1==0)
    {
        X = x2; Y = y2; ll ans = 0;
        ans -= ps_small[min(X,1LL)][min(Y,1LL)];
        ans+=ps_small_left[X][min(Y,1LL)];
        ans+=ps_small_up[min(X,1LL)][Y];
        X-=2; Y-=2;
        if(X<0 || Y<0) {return ans;}
        if(X>Y) 
        {
            ans+=(Y+1)*(psX[X-Y]-psX[0]);
            ans+=((Y+1)*psY[Y]-psY_temp[Y]);
            ans+=((X+1)*(psX[X]-psX[X-Y])-(psX_temp[X]-psX_temp[X-Y]));
        }
        else 
        {
            if(Y>X) {ans+=(X+1)*(psY[Y-X]-psY[0]);}
            ans+=((X+1)*psX[X]-psX_temp[X]);
            ans+=((Y+1)*(psY[Y]-psY[Y-X])-(psY_temp[Y]-psY_temp[Y-X]));
        }
        return ans;
    }
    else
    {
        ll ans = PS(0,x2,0,y2);
        if(x1>0) {ans-=PS(0,x1-1,0,y2);}
        if(y1>0) {ans-=PS(0,x2,0,y1-1);}
        if(x1>0 && y1>0) {ans+=PS(0,x1-1,0,y1-1);}
        return ans;
    }
}

vector<long long> mosaic(vector<int> XX, vector<int> YY, vector<int> T, vector<int> B, vector<int> L, vector<int> R) 
{
    ll N =  XX.size(); ll Q = T.size();
    if(N==1)
    {
        vector<ll> ans(Q,0); REP(q,0,Q) {ans[q]=XX[0];} return ans;
    }
    else if(N==2)
    {
        vector<vector<ll> > a(2,vector<ll>(2)); a[0][0]=XX[0]; a[0][1]=XX[1]; a[1][0]=YY[1]; a[1][1]=f(XX[1],YY[1]);
        vector<ll> ans(Q,0);
        REP(q,0,Q)
        {
            REP(i,0,2)
            {
                REP(j,0,2)
                {
                    if(i>=T[q] && i<=B[q] && j>= L[q] && j<=R[q] && a[i][j]==1) {ans[q]++;}
                }
            }
        }
        return ans;
    }

    vector<ll> X(N-2,0), Y(N-2,0);

    vector<vector<ll> > a;

    a.clear(); a= vector<vector<ll> >(3,vector<ll>(3,0)); ps_small = vector<vector<ll> >(2,vector<ll>(2,0));
    REP(i,0,3)
    {
        REP(j,0,3)
        {
            if(i==0) {a[i][j]=XX[j];} else if(j==0) {a[i][j]=YY[i];} else {a[i][j]=f(a[i][j-1],a[i-1][j]);}
            if(i==0 && j==0) {ps_small[i][j]=a[i][j];}
            else if(i==0 && j<=1) {ps_small[i][j]=ps_small[i][j-1]+a[i][j];}
            else if(j==0 && i<=1) {ps_small[i][j]=ps_small[i-1][j]+a[i][j];}
            else if(i<=1 && j<=1) {ps_small[i][j]=a[i][j]+ps_small[i-1][j]+ps_small[i][j-1]-ps_small[i-1][j-1];}
        }
    }

    X[0]=a[2][2]; Y[0]=a[2][2];

    a.clear(); a= vector<vector<ll> >(N,vector<ll>(2,0)); ps_small_left = vector<vector<ll> >(N,vector<ll>(2,0));
    REP(i,0,N)
    {
        REP(j,0,2)
        {
            if(i==0) {a[i][j]=XX[j];} else if(j==0) {a[i][j]=YY[i];} else {a[i][j]=f(a[i][j-1],a[i-1][j]);}
            if(i==0 && j==0) {ps_small_left[i][j]=a[i][j];}
            else if(i==0) {ps_small_left[i][j]=ps_small_left[i][j-1]+a[i][j];}
            else if(j==0) {ps_small_left[i][j]=ps_small_left[i-1][j]+a[i][j];}
            else {ps_small_left[i][j]=a[i][j]+ps_small_left[i-1][j]+ps_small_left[i][j-1]-ps_small_left[i-1][j-1];}
        }
    }

    REP(i,1,N-2)
    {
        X[i]=f(X[i-1],a[i+2][1]);
    }

    a.clear(); a= vector<vector<ll> >(2,vector<ll>(N,0)); ps_small_up = vector<vector<ll> >(2,vector<ll>(N,0));
    REP(i,0,2)
    {
        REP(j,0,N)
        {
            if(i==0) {a[i][j]=XX[j];} else if(j==0) {a[i][j]=YY[i];} else {a[i][j]=f(a[i][j-1],a[i-1][j]);}
            if(i==0 && j==0) {ps_small_up[i][j]=a[i][j];}
            else if(i==0) {ps_small_up[i][j]=ps_small_up[i][j-1]+a[i][j];}
            else if(j==0) {ps_small_up[i][j]=ps_small_up[i-1][j]+a[i][j];}
            else {ps_small_up[i][j]=a[i][j]+ps_small_up[i-1][j]+ps_small_up[i][j-1]-ps_small_up[i-1][j-1];}
        }
    }

    REP(i,1,N-2)
    {
        Y[i]=f(Y[i-1],a[1][i+2]);
    }

    ll cursum;

    cursum=0; REP(i,0,N-2) {cursum+=X[i]; psX.pb(cursum);}
    cursum=0; REP(i,0,N-2) {cursum+=Y[i]; psY.pb(cursum);}
    cursum=0; REP(i,0,N-2) {cursum+=(i*X[i]); psX_temp.pb(cursum);}
    cursum=0; REP(i,0,N-2) {cursum+=(i*Y[i]); psY_temp.pb(cursum);}

    vector<ll> ans(Q,0);
    REP(q,0,Q)
    {
        ans[q]=PS(T[q],B[q],L[q],R[q]);
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 508 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 508 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 504 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 125 ms 41156 KB Output is correct
2 Correct 121 ms 41416 KB Output is correct
3 Correct 119 ms 39416 KB Output is correct
4 Correct 120 ms 39416 KB Output is correct
5 Correct 89 ms 24548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 508 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 504 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 72 ms 12872 KB Output is correct
19 Correct 72 ms 12616 KB Output is correct
20 Correct 69 ms 12368 KB Output is correct
21 Correct 70 ms 12360 KB Output is correct
22 Correct 71 ms 12372 KB Output is correct
23 Correct 71 ms 11848 KB Output is correct
24 Correct 62 ms 12104 KB Output is correct
25 Correct 72 ms 12112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 62 ms 8264 KB Output is correct
2 Correct 180 ms 46792 KB Output is correct
3 Correct 140 ms 44536 KB Output is correct
4 Correct 163 ms 44788 KB Output is correct
5 Correct 124 ms 44788 KB Output is correct
6 Correct 142 ms 45428 KB Output is correct
7 Correct 163 ms 45436 KB Output is correct
8 Correct 139 ms 47284 KB Output is correct
9 Correct 102 ms 29536 KB Output is correct
10 Correct 97 ms 29500 KB Output is correct
11 Correct 103 ms 29500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 140 ms 44284 KB Output is correct
2 Correct 148 ms 45304 KB Output is correct
3 Correct 137 ms 43768 KB Output is correct
4 Correct 139 ms 43768 KB Output is correct
5 Correct 122 ms 45820 KB Output is correct
6 Correct 114 ms 29728 KB Output is correct
7 Correct 94 ms 22288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 125 ms 41156 KB Output is correct
2 Correct 121 ms 41416 KB Output is correct
3 Correct 119 ms 39416 KB Output is correct
4 Correct 120 ms 39416 KB Output is correct
5 Correct 89 ms 24548 KB Output is correct
6 Correct 140 ms 44284 KB Output is correct
7 Correct 148 ms 45304 KB Output is correct
8 Correct 137 ms 43768 KB Output is correct
9 Correct 139 ms 43768 KB Output is correct
10 Correct 122 ms 45820 KB Output is correct
11 Correct 114 ms 29728 KB Output is correct
12 Correct 94 ms 22288 KB Output is correct
13 Correct 169 ms 46836 KB Output is correct
14 Correct 143 ms 46956 KB Output is correct
15 Correct 161 ms 45560 KB Output is correct
16 Correct 128 ms 43768 KB Output is correct
17 Correct 138 ms 44968 KB Output is correct
18 Correct 139 ms 45428 KB Output is correct
19 Correct 104 ms 25892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 508 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 504 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 125 ms 41156 KB Output is correct
20 Correct 121 ms 41416 KB Output is correct
21 Correct 119 ms 39416 KB Output is correct
22 Correct 120 ms 39416 KB Output is correct
23 Correct 89 ms 24548 KB Output is correct
24 Correct 72 ms 12872 KB Output is correct
25 Correct 72 ms 12616 KB Output is correct
26 Correct 69 ms 12368 KB Output is correct
27 Correct 70 ms 12360 KB Output is correct
28 Correct 71 ms 12372 KB Output is correct
29 Correct 71 ms 11848 KB Output is correct
30 Correct 62 ms 12104 KB Output is correct
31 Correct 72 ms 12112 KB Output is correct
32 Correct 62 ms 8264 KB Output is correct
33 Correct 180 ms 46792 KB Output is correct
34 Correct 140 ms 44536 KB Output is correct
35 Correct 163 ms 44788 KB Output is correct
36 Correct 124 ms 44788 KB Output is correct
37 Correct 142 ms 45428 KB Output is correct
38 Correct 163 ms 45436 KB Output is correct
39 Correct 139 ms 47284 KB Output is correct
40 Correct 102 ms 29536 KB Output is correct
41 Correct 97 ms 29500 KB Output is correct
42 Correct 103 ms 29500 KB Output is correct
43 Correct 140 ms 44284 KB Output is correct
44 Correct 148 ms 45304 KB Output is correct
45 Correct 137 ms 43768 KB Output is correct
46 Correct 139 ms 43768 KB Output is correct
47 Correct 122 ms 45820 KB Output is correct
48 Correct 114 ms 29728 KB Output is correct
49 Correct 94 ms 22288 KB Output is correct
50 Correct 169 ms 46836 KB Output is correct
51 Correct 143 ms 46956 KB Output is correct
52 Correct 161 ms 45560 KB Output is correct
53 Correct 128 ms 43768 KB Output is correct
54 Correct 138 ms 44968 KB Output is correct
55 Correct 139 ms 45428 KB Output is correct
56 Correct 104 ms 25892 KB Output is correct
57 Correct 185 ms 46840 KB Output is correct
58 Correct 149 ms 46652 KB Output is correct
59 Correct 169 ms 45360 KB Output is correct
60 Correct 137 ms 46520 KB Output is correct
61 Correct 185 ms 44544 KB Output is correct
62 Correct 146 ms 44792 KB Output is correct
63 Correct 114 ms 29472 KB Output is correct
64 Correct 101 ms 21336 KB Output is correct