답안 #1107549

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1107549 2024-11-01T12:44:35 Z Ahmed57 모자이크 (IOI24_mosaic) C++17
100 / 100
121 ms 37636 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
int arr1[3][200001];
int arr2[200001][3];
int ans[400001];
long long pref[400001];
long long suf[400001];
void upd(int x,int y,int val){
    if(x<3){
        arr1[x][y] = val;
    }
    if(y<3){
        arr2[x][y] = val;
    }
}
int get(int x,int y){
    if(x<3)return arr1[x][y];
    else return arr2[x][y];
}
vector<long long> mosaic(vector<int32_t> X, vector<int32_t> Y, vector<int32_t> T, vector<int32_t> B, vector<int32_t> L, vector<int32_t> R) {
    int n = X.size();
    for(int i = 0;i<n;i++){
        for(int j = 0;j<n;j++){
            if(i>=3&&j>=3)break;
            if(i==0){
                upd(i,j,X[j]);
            }else if(j==0){
                upd(i,j,Y[i]);
            }else{
                upd(i,j,((get(i-1,j)==0&&get(i,j-1)==0)?1:0));
            }
            ans[i-j+n] = get(i,j);
        }
    }
    for(int i = 0;i<2*n;i++){
        pref[i] = ans[i]*i;
        suf[i] = ans[i]*(2*n-i);
    }
    for(int i = 1;i<2*n;i++){
        ans[i]+=ans[i-1];
        pref[i]+=pref[i-1];
        suf[i]+=suf[i-1];
    }
    for(int i = 0;i<3;i++){
        for(int j = 1;j<n;j++){
            arr1[i][j]+=arr1[i][j-1];
            arr2[j][i]+=arr2[j-1][i];
        }
    }
    vector<int> anss;
    for(int i = 0;i<T.size();i++){
        int x1 = T[i] , x2 = B[i];
        int y1 = L[i] , y2 = R[i];
        long long all = 0;
        while(x1<=min(2ll,x2)){
            all+=arr1[x1][y2]-(y1==0?0:arr1[x1][y1-1]);
            x1++;
        }
        while(y1<=min(2ll,y2)){
            all+=arr2[x2][y1]-(x1==0?0:arr2[x1-1][y1]);
            y1++;
        }
        int mi = (x1-y2+n);
        int ma = (x2-y1+n);
        int lon = min(y2-y1+1,x2-x1+1);
        all+=(ans[ma-lon+1]-ans[mi+lon-2])*lon;
        if(lon>1){
            all+=(pref[mi+lon-2]-pref[mi-1])+(ans[mi+lon-2]-ans[mi-1])*(1-mi);
            all+=(suf[ma]-suf[ma-lon+1])+(ans[ma]-ans[ma-lon+1])*(1-(2*n-ma));
        }
        anss.push_back(all);
    }
    return anss;
}

Compilation message

mosaic.cpp: In function 'std::vector<long long int> mosaic(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
mosaic.cpp:52:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |     for(int i = 0;i<T.size();i++){
      |                   ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8528 KB Output is correct
2 Correct 1 ms 8528 KB Output is correct
3 Correct 2 ms 10576 KB Output is correct
4 Correct 2 ms 10576 KB Output is correct
5 Correct 2 ms 10576 KB Output is correct
6 Correct 1 ms 10576 KB Output is correct
7 Correct 2 ms 10576 KB Output is correct
8 Correct 2 ms 10576 KB Output is correct
9 Correct 2 ms 10692 KB Output is correct
10 Correct 2 ms 10576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8528 KB Output is correct
2 Correct 1 ms 8528 KB Output is correct
3 Correct 2 ms 10576 KB Output is correct
4 Correct 2 ms 10576 KB Output is correct
5 Correct 2 ms 10576 KB Output is correct
6 Correct 1 ms 10576 KB Output is correct
7 Correct 2 ms 10576 KB Output is correct
8 Correct 2 ms 10576 KB Output is correct
9 Correct 2 ms 10692 KB Output is correct
10 Correct 2 ms 10576 KB Output is correct
11 Correct 2 ms 12624 KB Output is correct
12 Correct 2 ms 12624 KB Output is correct
13 Correct 2 ms 12796 KB Output is correct
14 Correct 2 ms 12624 KB Output is correct
15 Correct 2 ms 12624 KB Output is correct
16 Correct 2 ms 12748 KB Output is correct
17 Correct 2 ms 12792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 90 ms 31636 KB Output is correct
2 Correct 85 ms 31676 KB Output is correct
3 Correct 87 ms 31676 KB Output is correct
4 Correct 84 ms 31632 KB Output is correct
5 Correct 69 ms 29884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8528 KB Output is correct
2 Correct 1 ms 8528 KB Output is correct
3 Correct 2 ms 10576 KB Output is correct
4 Correct 2 ms 10576 KB Output is correct
5 Correct 2 ms 10576 KB Output is correct
6 Correct 1 ms 10576 KB Output is correct
7 Correct 2 ms 10576 KB Output is correct
8 Correct 2 ms 10576 KB Output is correct
9 Correct 2 ms 10692 KB Output is correct
10 Correct 2 ms 10576 KB Output is correct
11 Correct 2 ms 12624 KB Output is correct
12 Correct 2 ms 12624 KB Output is correct
13 Correct 2 ms 12796 KB Output is correct
14 Correct 2 ms 12624 KB Output is correct
15 Correct 2 ms 12624 KB Output is correct
16 Correct 2 ms 12748 KB Output is correct
17 Correct 2 ms 12792 KB Output is correct
18 Correct 64 ms 28100 KB Output is correct
19 Correct 59 ms 27844 KB Output is correct
20 Correct 60 ms 27796 KB Output is correct
21 Correct 72 ms 27588 KB Output is correct
22 Correct 77 ms 27588 KB Output is correct
23 Correct 62 ms 25796 KB Output is correct
24 Correct 60 ms 25852 KB Output is correct
25 Correct 59 ms 25712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 51 ms 22212 KB Output is correct
2 Correct 95 ms 37636 KB Output is correct
3 Correct 108 ms 36924 KB Output is correct
4 Correct 90 ms 36796 KB Output is correct
5 Correct 104 ms 37056 KB Output is correct
6 Correct 90 ms 37508 KB Output is correct
7 Correct 90 ms 37520 KB Output is correct
8 Correct 100 ms 37444 KB Output is correct
9 Correct 88 ms 34924 KB Output is correct
10 Correct 82 ms 35004 KB Output is correct
11 Correct 81 ms 35004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 101 ms 31724 KB Output is correct
2 Correct 101 ms 31676 KB Output is correct
3 Correct 87 ms 31680 KB Output is correct
4 Correct 86 ms 31676 KB Output is correct
5 Correct 96 ms 34996 KB Output is correct
6 Correct 83 ms 32956 KB Output is correct
7 Correct 78 ms 31932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 90 ms 31636 KB Output is correct
2 Correct 85 ms 31676 KB Output is correct
3 Correct 87 ms 31676 KB Output is correct
4 Correct 84 ms 31632 KB Output is correct
5 Correct 69 ms 29884 KB Output is correct
6 Correct 101 ms 31724 KB Output is correct
7 Correct 101 ms 31676 KB Output is correct
8 Correct 87 ms 31680 KB Output is correct
9 Correct 86 ms 31676 KB Output is correct
10 Correct 96 ms 34996 KB Output is correct
11 Correct 83 ms 32956 KB Output is correct
12 Correct 78 ms 31932 KB Output is correct
13 Correct 108 ms 31680 KB Output is correct
14 Correct 95 ms 34704 KB Output is correct
15 Correct 98 ms 35004 KB Output is correct
16 Correct 98 ms 31636 KB Output is correct
17 Correct 93 ms 34628 KB Output is correct
18 Correct 97 ms 31676 KB Output is correct
19 Correct 73 ms 29648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12624 KB Output is correct
2 Correct 2 ms 8528 KB Output is correct
3 Correct 1 ms 8528 KB Output is correct
4 Correct 2 ms 10576 KB Output is correct
5 Correct 2 ms 10576 KB Output is correct
6 Correct 2 ms 10576 KB Output is correct
7 Correct 1 ms 10576 KB Output is correct
8 Correct 2 ms 10576 KB Output is correct
9 Correct 2 ms 10576 KB Output is correct
10 Correct 2 ms 10692 KB Output is correct
11 Correct 2 ms 10576 KB Output is correct
12 Correct 2 ms 12624 KB Output is correct
13 Correct 2 ms 12624 KB Output is correct
14 Correct 2 ms 12796 KB Output is correct
15 Correct 2 ms 12624 KB Output is correct
16 Correct 2 ms 12624 KB Output is correct
17 Correct 2 ms 12748 KB Output is correct
18 Correct 2 ms 12792 KB Output is correct
19 Correct 90 ms 31636 KB Output is correct
20 Correct 85 ms 31676 KB Output is correct
21 Correct 87 ms 31676 KB Output is correct
22 Correct 84 ms 31632 KB Output is correct
23 Correct 69 ms 29884 KB Output is correct
24 Correct 64 ms 28100 KB Output is correct
25 Correct 59 ms 27844 KB Output is correct
26 Correct 60 ms 27796 KB Output is correct
27 Correct 72 ms 27588 KB Output is correct
28 Correct 77 ms 27588 KB Output is correct
29 Correct 62 ms 25796 KB Output is correct
30 Correct 60 ms 25852 KB Output is correct
31 Correct 59 ms 25712 KB Output is correct
32 Correct 51 ms 22212 KB Output is correct
33 Correct 95 ms 37636 KB Output is correct
34 Correct 108 ms 36924 KB Output is correct
35 Correct 90 ms 36796 KB Output is correct
36 Correct 104 ms 37056 KB Output is correct
37 Correct 90 ms 37508 KB Output is correct
38 Correct 90 ms 37520 KB Output is correct
39 Correct 100 ms 37444 KB Output is correct
40 Correct 88 ms 34924 KB Output is correct
41 Correct 82 ms 35004 KB Output is correct
42 Correct 81 ms 35004 KB Output is correct
43 Correct 101 ms 31724 KB Output is correct
44 Correct 101 ms 31676 KB Output is correct
45 Correct 87 ms 31680 KB Output is correct
46 Correct 86 ms 31676 KB Output is correct
47 Correct 96 ms 34996 KB Output is correct
48 Correct 83 ms 32956 KB Output is correct
49 Correct 78 ms 31932 KB Output is correct
50 Correct 108 ms 31680 KB Output is correct
51 Correct 95 ms 34704 KB Output is correct
52 Correct 98 ms 35004 KB Output is correct
53 Correct 98 ms 31636 KB Output is correct
54 Correct 93 ms 34628 KB Output is correct
55 Correct 97 ms 31676 KB Output is correct
56 Correct 73 ms 29648 KB Output is correct
57 Correct 113 ms 37564 KB Output is correct
58 Correct 121 ms 37052 KB Output is correct
59 Correct 100 ms 37432 KB Output is correct
60 Correct 101 ms 36932 KB Output is correct
61 Correct 102 ms 36796 KB Output is correct
62 Correct 103 ms 37060 KB Output is correct
63 Correct 84 ms 35016 KB Output is correct
64 Correct 79 ms 33916 KB Output is correct