답안 #710724

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
710724 2023-03-15T17:10:05 Z Ronin13 Crossing (JOI21_crossing) C++14
100 / 100
1962 ms 27536 KB
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
using namespace std;
const int nmax = 1000001;
map <vector <int>, bool> used;
vector <vector <int> >  vec;

vector <int> op(vector <int> &a, vector <int> &b){
    vector <int> ans;
    for(int i = 0; i < a.size(); i++){
        int x = a[i] + b[i];
        x = -x;
        x %= 3;
        x += 3;
        x %= 3;
        ans.pb(x);
    }
    return ans;
}

void rec(vector <int> &v){
    used[v] = true;
    vec.pb(v);
    vector <vector <int> > q;
    for(auto to : vec){
        vector <int> x = op(to, v);
        if(used[x]) continue;
        q.push_back(x);
        used[x] = true;
    }
    for(auto to : q)
        rec(to);
}

int L[nmax], R[nmax];

int blsize = 501;

bool good[nmax][10];
int val[nmax];
int opt[nmax][10];

vector <int> b;

void update_block(int ind, int v, int bl){
    if(opt[bl][ind] == v)
        good[bl][ind] = true;
    else good[bl][ind] = false;
    val[bl] = v;
}

void fil(int bl){
    if(val[bl] == -1) return;
    for(int i = L[bl]; i <= R[bl]; i++)
        b[i] = val[bl];
    val[bl] = -1;
}

bool check(int bl, int ind){
    for(int i = L[bl]; i <= R[bl]; i++){
        if(b[i] != vec[ind][i]) return false;
    }
    return true;
}

void update_ran(int ind, int l, int r, int v){
    int bl = l / blsize;
    good[bl][ind] = false;
    fil(bl);
    for(int i = l; i <= r; i++)
        b[i] = v;
    good[bl][ind] = check(bl, ind);
}

bool CH(int sz){
    bool ans = false;
    for(int j = 0; j < vec.size(); j++){
        bool cur = true;
        for(int i= 0; i <= sz; i++){
            cur &= good[i][j];
        }
        ans |= cur;
    }
    return ans;
}

int main(){
   // ios_base::sync_with_stdio(false); cin.tie(0);
    int n; cin >> n;
    int cur = 1;
    int curbl = 0;
    L[0] = 0;
    blsize = sqrt(n);
    for(int i = 1; i < n; i++){
        if(cur + 1 > blsize){
            R[curbl] = i - 1;
            cur = 1;
            L[++curbl] = i;
        }
        else cur++;
    }
    R[curbl] = n - 1;
    for(int i = 0; i <= curbl ;i++)
        val[i] = -1;
    string a[3];
    for(int i = 0; i < 3; i++){
        vector<int> v;
        cin >> a[i];
        for(int j = 0; j < n; j++){
            if(a[i][j] == 'O')
                v.pb(0);
            if(a[i][j] == 'J')
                v.pb(1);
            if(a[i][j] == 'I')
                v.pb(2);
        }
        //used[v] = true;
        rec(v);
        //vec.pb(v);
    }
   // cout << vec.size() << "\n";
    int q; cin >> q;
    for(int i = 0; i < n; i++){
        char c; cin >> c;
        if(c == 'J')
            b.pb(1);
        if(c == 'O')
            b.pb(0);
        if(c == 'I')
            b.pb(2);
    }
   // cout << vec.size();
    for(int i = 0; i < n; i++){
        for(int j = 0; j < vec.size(); j++)
            update_ran(j, i, i, b[i]);
    }
    for(int j = 0; j < vec.size(); j++){
        for(int i = 0; i <= curbl; i++){
            opt[i][j] = vec[j][L[i]];
            for(int x = L[i] + 1; x <= R[i]; x++)
                if(vec[j][x] != vec[j][x - 1])
                    opt[i][j] = -1;
        }
    }
    CH(curbl) ? cout << "Yes\n" : cout << "No\n";
    while(q--){
        int l,r; cin >> l >> r;
        char c; cin >> c;
        int x;
        if(c == 'O')
            x = 0;
        if(c == 'J')
            x = 1;
        if(c == 'I')
            x = 2;
        l--, r--;
        int X = l / blsize;
        int Y = r / blsize;
        if(X == Y){
            for(int j = 0; j < vec.size(); j++)
                update_ran(j, l, r, x);
        }
        else{
            for(int i = X + 1; i < Y; i++){
                for(int j = 0; j < vec.size(); j++)
                    update_block(j, x, i);
            }
            for(int j = 0; j < vec.size(); j++){
                update_ran(j, l, R[X], x);
                update_ran(j, L[Y], r, x);
            }
        }
        CH(curbl) ? cout << "Yes\n" : cout << "No\n";
    }
    return 0;
}

Compilation message

Main.cpp: In function 'std::vector<int> op(std::vector<int>&, std::vector<int>&)':
Main.cpp:17:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |     for(int i = 0; i < a.size(); i++){
      |                    ~~^~~~~~~~~~
Main.cpp: In function 'bool CH(int)':
Main.cpp:84:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |     for(int j = 0; j < vec.size(); j++){
      |                    ~~^~~~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:141:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  141 |         for(int j = 0; j < vec.size(); j++)
      |                        ~~^~~~~~~~~~~~
Main.cpp:144:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  144 |     for(int j = 0; j < vec.size(); j++){
      |                    ~~^~~~~~~~~~~~
Main.cpp:167:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  167 |             for(int j = 0; j < vec.size(); j++)
      |                            ~~^~~~~~~~~~~~
Main.cpp:172:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  172 |                 for(int j = 0; j < vec.size(); j++)
      |                                ~~^~~~~~~~~~~~
Main.cpp:175:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  175 |             for(int j = 0; j < vec.size(); j++){
      |                            ~~^~~~~~~~~~~~
Main.cpp:53:5: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
   53 |     if(opt[bl][ind] == v)
      |     ^~
Main.cpp:156:13: note: 'x' was declared here
  156 |         int x;
      |             ^
# 결과 실행 시간 메모리 Grader output
1 Correct 323 ms 1088 KB Output is correct
2 Correct 361 ms 1124 KB Output is correct
3 Correct 376 ms 916 KB Output is correct
4 Correct 337 ms 964 KB Output is correct
5 Correct 346 ms 1000 KB Output is correct
6 Correct 324 ms 832 KB Output is correct
7 Correct 351 ms 1024 KB Output is correct
8 Correct 364 ms 984 KB Output is correct
9 Correct 374 ms 900 KB Output is correct
10 Correct 354 ms 876 KB Output is correct
11 Correct 364 ms 844 KB Output is correct
12 Correct 349 ms 1028 KB Output is correct
13 Correct 337 ms 888 KB Output is correct
14 Correct 359 ms 816 KB Output is correct
15 Correct 347 ms 900 KB Output is correct
16 Correct 353 ms 856 KB Output is correct
17 Correct 345 ms 900 KB Output is correct
18 Correct 388 ms 852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 323 ms 1088 KB Output is correct
2 Correct 361 ms 1124 KB Output is correct
3 Correct 376 ms 916 KB Output is correct
4 Correct 337 ms 964 KB Output is correct
5 Correct 346 ms 1000 KB Output is correct
6 Correct 324 ms 832 KB Output is correct
7 Correct 351 ms 1024 KB Output is correct
8 Correct 364 ms 984 KB Output is correct
9 Correct 374 ms 900 KB Output is correct
10 Correct 354 ms 876 KB Output is correct
11 Correct 364 ms 844 KB Output is correct
12 Correct 349 ms 1028 KB Output is correct
13 Correct 337 ms 888 KB Output is correct
14 Correct 359 ms 816 KB Output is correct
15 Correct 347 ms 900 KB Output is correct
16 Correct 353 ms 856 KB Output is correct
17 Correct 345 ms 900 KB Output is correct
18 Correct 388 ms 852 KB Output is correct
19 Correct 837 ms 8192 KB Output is correct
20 Correct 1012 ms 8256 KB Output is correct
21 Correct 668 ms 7272 KB Output is correct
22 Correct 583 ms 9160 KB Output is correct
23 Correct 418 ms 3724 KB Output is correct
24 Correct 423 ms 3816 KB Output is correct
25 Correct 624 ms 11904 KB Output is correct
26 Correct 634 ms 11872 KB Output is correct
27 Correct 811 ms 11792 KB Output is correct
28 Correct 764 ms 11888 KB Output is correct
29 Correct 848 ms 10120 KB Output is correct
30 Correct 441 ms 3520 KB Output is correct
31 Correct 819 ms 11864 KB Output is correct
32 Correct 682 ms 9864 KB Output is correct
33 Correct 418 ms 3668 KB Output is correct
34 Correct 684 ms 12008 KB Output is correct
35 Correct 551 ms 8740 KB Output is correct
36 Correct 417 ms 3520 KB Output is correct
37 Correct 421 ms 3592 KB Output is correct
38 Correct 1044 ms 11656 KB Output is correct
39 Correct 764 ms 11856 KB Output is correct
40 Correct 590 ms 7924 KB Output is correct
41 Correct 1100 ms 12124 KB Output is correct
42 Correct 1111 ms 11332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 323 ms 1088 KB Output is correct
2 Correct 361 ms 1124 KB Output is correct
3 Correct 376 ms 916 KB Output is correct
4 Correct 337 ms 964 KB Output is correct
5 Correct 346 ms 1000 KB Output is correct
6 Correct 324 ms 832 KB Output is correct
7 Correct 351 ms 1024 KB Output is correct
8 Correct 364 ms 984 KB Output is correct
9 Correct 374 ms 900 KB Output is correct
10 Correct 354 ms 876 KB Output is correct
11 Correct 364 ms 844 KB Output is correct
12 Correct 349 ms 1028 KB Output is correct
13 Correct 337 ms 888 KB Output is correct
14 Correct 359 ms 816 KB Output is correct
15 Correct 347 ms 900 KB Output is correct
16 Correct 353 ms 856 KB Output is correct
17 Correct 345 ms 900 KB Output is correct
18 Correct 388 ms 852 KB Output is correct
19 Correct 399 ms 836 KB Output is correct
20 Correct 439 ms 932 KB Output is correct
21 Correct 350 ms 932 KB Output is correct
22 Correct 322 ms 924 KB Output is correct
23 Correct 374 ms 876 KB Output is correct
24 Correct 372 ms 844 KB Output is correct
25 Correct 378 ms 896 KB Output is correct
26 Correct 358 ms 912 KB Output is correct
27 Correct 359 ms 808 KB Output is correct
28 Correct 333 ms 832 KB Output is correct
29 Correct 378 ms 924 KB Output is correct
30 Correct 344 ms 868 KB Output is correct
31 Correct 400 ms 920 KB Output is correct
32 Correct 397 ms 884 KB Output is correct
33 Correct 399 ms 888 KB Output is correct
34 Correct 377 ms 924 KB Output is correct
35 Correct 405 ms 928 KB Output is correct
36 Correct 429 ms 832 KB Output is correct
37 Correct 402 ms 968 KB Output is correct
38 Correct 413 ms 868 KB Output is correct
39 Correct 425 ms 940 KB Output is correct
40 Correct 422 ms 916 KB Output is correct
41 Correct 458 ms 936 KB Output is correct
42 Correct 411 ms 884 KB Output is correct
43 Correct 400 ms 916 KB Output is correct
44 Correct 442 ms 840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 323 ms 1088 KB Output is correct
2 Correct 361 ms 1124 KB Output is correct
3 Correct 376 ms 916 KB Output is correct
4 Correct 337 ms 964 KB Output is correct
5 Correct 346 ms 1000 KB Output is correct
6 Correct 324 ms 832 KB Output is correct
7 Correct 351 ms 1024 KB Output is correct
8 Correct 364 ms 984 KB Output is correct
9 Correct 374 ms 900 KB Output is correct
10 Correct 354 ms 876 KB Output is correct
11 Correct 364 ms 844 KB Output is correct
12 Correct 349 ms 1028 KB Output is correct
13 Correct 337 ms 888 KB Output is correct
14 Correct 359 ms 816 KB Output is correct
15 Correct 347 ms 900 KB Output is correct
16 Correct 353 ms 856 KB Output is correct
17 Correct 345 ms 900 KB Output is correct
18 Correct 388 ms 852 KB Output is correct
19 Correct 837 ms 8192 KB Output is correct
20 Correct 1012 ms 8256 KB Output is correct
21 Correct 668 ms 7272 KB Output is correct
22 Correct 583 ms 9160 KB Output is correct
23 Correct 418 ms 3724 KB Output is correct
24 Correct 423 ms 3816 KB Output is correct
25 Correct 624 ms 11904 KB Output is correct
26 Correct 634 ms 11872 KB Output is correct
27 Correct 811 ms 11792 KB Output is correct
28 Correct 764 ms 11888 KB Output is correct
29 Correct 848 ms 10120 KB Output is correct
30 Correct 441 ms 3520 KB Output is correct
31 Correct 819 ms 11864 KB Output is correct
32 Correct 682 ms 9864 KB Output is correct
33 Correct 418 ms 3668 KB Output is correct
34 Correct 684 ms 12008 KB Output is correct
35 Correct 551 ms 8740 KB Output is correct
36 Correct 417 ms 3520 KB Output is correct
37 Correct 421 ms 3592 KB Output is correct
38 Correct 1044 ms 11656 KB Output is correct
39 Correct 764 ms 11856 KB Output is correct
40 Correct 590 ms 7924 KB Output is correct
41 Correct 1100 ms 12124 KB Output is correct
42 Correct 1111 ms 11332 KB Output is correct
43 Correct 399 ms 836 KB Output is correct
44 Correct 439 ms 932 KB Output is correct
45 Correct 350 ms 932 KB Output is correct
46 Correct 322 ms 924 KB Output is correct
47 Correct 374 ms 876 KB Output is correct
48 Correct 372 ms 844 KB Output is correct
49 Correct 378 ms 896 KB Output is correct
50 Correct 358 ms 912 KB Output is correct
51 Correct 359 ms 808 KB Output is correct
52 Correct 333 ms 832 KB Output is correct
53 Correct 378 ms 924 KB Output is correct
54 Correct 344 ms 868 KB Output is correct
55 Correct 400 ms 920 KB Output is correct
56 Correct 397 ms 884 KB Output is correct
57 Correct 399 ms 888 KB Output is correct
58 Correct 377 ms 924 KB Output is correct
59 Correct 405 ms 928 KB Output is correct
60 Correct 429 ms 832 KB Output is correct
61 Correct 402 ms 968 KB Output is correct
62 Correct 413 ms 868 KB Output is correct
63 Correct 425 ms 940 KB Output is correct
64 Correct 422 ms 916 KB Output is correct
65 Correct 458 ms 936 KB Output is correct
66 Correct 411 ms 884 KB Output is correct
67 Correct 400 ms 916 KB Output is correct
68 Correct 442 ms 840 KB Output is correct
69 Correct 1313 ms 23384 KB Output is correct
70 Correct 1909 ms 27264 KB Output is correct
71 Correct 457 ms 3932 KB Output is correct
72 Correct 440 ms 3752 KB Output is correct
73 Correct 454 ms 3764 KB Output is correct
74 Correct 668 ms 11172 KB Output is correct
75 Correct 434 ms 3848 KB Output is correct
76 Correct 698 ms 13424 KB Output is correct
77 Correct 633 ms 11244 KB Output is correct
78 Correct 453 ms 3820 KB Output is correct
79 Correct 429 ms 3748 KB Output is correct
80 Correct 896 ms 20144 KB Output is correct
81 Correct 543 ms 4536 KB Output is correct
82 Correct 1046 ms 27256 KB Output is correct
83 Correct 1020 ms 23640 KB Output is correct
84 Correct 532 ms 4408 KB Output is correct
85 Correct 544 ms 4436 KB Output is correct
86 Correct 1195 ms 21108 KB Output is correct
87 Correct 1286 ms 27356 KB Output is correct
88 Correct 639 ms 4496 KB Output is correct
89 Correct 1148 ms 25012 KB Output is correct
90 Correct 1223 ms 27332 KB Output is correct
91 Correct 604 ms 4448 KB Output is correct
92 Correct 859 ms 20912 KB Output is correct
93 Correct 612 ms 4352 KB Output is correct
94 Correct 532 ms 4596 KB Output is correct
95 Correct 551 ms 4348 KB Output is correct
96 Correct 1112 ms 11708 KB Output is correct
97 Correct 1572 ms 27372 KB Output is correct
98 Correct 912 ms 18480 KB Output is correct
99 Correct 1843 ms 27536 KB Output is correct
100 Correct 1962 ms 26672 KB Output is correct