답안 #419991

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
419991 2021-06-07T21:06:43 Z davi_bart Crossing (JOI21_crossing) C++17
100 / 100
4321 ms 8832 KB
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define fi first
#define se second
#define ld long double
#define pb push_back
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int N,Q;
set<string> k;
string a,b,c;
string t;
vector<vector<int> > h;
const int dim=200;
const int p=257,mod=1e9+9;
vector<int> pot;
vector<int> tt;
map<char,int> val;
vector<char> qq(1000010,'x');
int hasha(string q){
    int l=0;
    for(auto k:q)l=(l*p+k)%mod;
    for(int i=q.size();i<dim;i++)l=l*p%mod;
    return l;
}
void solve(){
    for(auto v:h){
        bool ok=1;
        for(int i=0;i<v.size();i++)if(v[i]!=tt[i])ok=0;
        if(ok){
            cout<<"Yes\n";
            return;
        }
    }
    cout<<"No\n";
}
string cross(string x,string y){
    string ans="";
    vector<char> s={'I','J','O'};
    for(int i=0;i<x.size();i++){
        if(x[i]==y[i])ans+=x[i];
        else{
            for(auto h:s)if(x[i]!=h && y[i]!=h)ans+=h;
        }
    }
    return ans;
}
void calc(){
    while(1){
        bool ok=0;
        for(auto x:k){
            for(auto y:k){
                string h=cross(x,y);
                if(k.count(h))continue;
                ok=1;
                k.insert(h);
            }
        }
        if(!ok)break;
    }
}
signed main(){
	ios::sync_with_stdio(false);cin.tie(0);
    cin>>N>>a>>b>>c>>Q>>t;
    k.insert(a);k.insert(b);k.insert(c);
    calc();
    assert(k.size()<10);
    pot={1};
    for(int i=0;i<300010;i++)pot.pb(pot.back()*p%mod);

    val['I']=hasha(string(dim,'I'));
    val['J']=hasha(string(dim,'J'));
    val['O']=hasha(string(dim,'O'));

    for(auto y:k){
        h.pb(vector<int> ());
        for(int i=0;i*dim<N;i++){
            string cur="";
            for(int j=dim*i;j<min(N,dim*(i+1));j++){
                cur+=y[j];
            }
            h.back().pb(hasha(cur));
            //cout<<"iniziali: "<<h.back().back()<<endl;
        }
    }
    for(int i=0;i*dim<N;i++){
        string cur="";
        for(int j=dim*i;j<min(N,dim*(i+1));j++){
            cur+=t[j];
        }
        tt.pb(hasha(cur));
    }
    //cout<<tt[0]<<" "<<hasha(t)<<endl;
    solve();
    for(int i=0;i<Q;i++){
        int x,y;
        char z;
        cin>>x>>y>>z;
        x--;y--;
        int pos=x-x%dim;
        for(int j=pos;j<min(N,pos+dim);j++){
            int pp=j/dim;
            if(qq[pp]!='x')t[j]=qq[pp];

            tt[pp]-=t[j]*pot[dim-j%dim-1];
            if(j>=x && j<=y)t[j]=z;
            tt[pp]+=t[j]*pot[dim-j%dim-1];
            tt[pp]=(tt[pp]%mod+mod)%mod;
        }
        qq[pos/dim]='x';

        x=x-x%dim+dim;

        pos=y-y%dim;
        for(int j=pos;j<min(N,pos+dim);j++){
            int pp=j/dim;
            if(qq[pp]!='x')t[j]=qq[pp];

            tt[pp]-=t[j]*pot[dim-j%dim-1];
            if(j>=x && j<=y)t[j]=z;
            tt[pp]+=t[j]*pot[dim-j%dim-1];
            tt[pp]=(tt[pp]%mod+mod)%mod;
        }
        y=y-y%dim;
        qq[pos/dim]='x';

        for(int j=x;j<y;j+=dim){
            int pp=j/dim;
            tt[pp]=val[z];
            qq[pp]=z;
        }

        //cout<<tt[0]<<" "<<hasha(t)<<endl;
        solve();
    }
}

Compilation message

Main.cpp: In function 'void solve()':
Main.cpp:31:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |         for(int i=0;i<v.size();i++)if(v[i]!=tt[i])ok=0;
      |                     ~^~~~~~~~~
Main.cpp: In function 'std::string cross(std::string, std::string)':
Main.cpp:42:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |     for(int i=0;i<x.size();i++){
      |                 ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 411 ms 5484 KB Output is correct
2 Correct 544 ms 5444 KB Output is correct
3 Correct 572 ms 5444 KB Output is correct
4 Correct 508 ms 5444 KB Output is correct
5 Correct 477 ms 5444 KB Output is correct
6 Correct 492 ms 5444 KB Output is correct
7 Correct 414 ms 5444 KB Output is correct
8 Correct 539 ms 5444 KB Output is correct
9 Correct 536 ms 5444 KB Output is correct
10 Correct 536 ms 5444 KB Output is correct
11 Correct 537 ms 5444 KB Output is correct
12 Correct 537 ms 5444 KB Output is correct
13 Correct 540 ms 5444 KB Output is correct
14 Correct 541 ms 5444 KB Output is correct
15 Correct 545 ms 5532 KB Output is correct
16 Correct 543 ms 5444 KB Output is correct
17 Correct 538 ms 5444 KB Output is correct
18 Correct 569 ms 5444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 411 ms 5484 KB Output is correct
2 Correct 544 ms 5444 KB Output is correct
3 Correct 572 ms 5444 KB Output is correct
4 Correct 508 ms 5444 KB Output is correct
5 Correct 477 ms 5444 KB Output is correct
6 Correct 492 ms 5444 KB Output is correct
7 Correct 414 ms 5444 KB Output is correct
8 Correct 539 ms 5444 KB Output is correct
9 Correct 536 ms 5444 KB Output is correct
10 Correct 536 ms 5444 KB Output is correct
11 Correct 537 ms 5444 KB Output is correct
12 Correct 537 ms 5444 KB Output is correct
13 Correct 540 ms 5444 KB Output is correct
14 Correct 541 ms 5444 KB Output is correct
15 Correct 545 ms 5532 KB Output is correct
16 Correct 543 ms 5444 KB Output is correct
17 Correct 538 ms 5444 KB Output is correct
18 Correct 569 ms 5444 KB Output is correct
19 Correct 1462 ms 6608 KB Output is correct
20 Correct 2394 ms 6608 KB Output is correct
21 Correct 1160 ms 6588 KB Output is correct
22 Correct 1133 ms 6480 KB Output is correct
23 Correct 1033 ms 5564 KB Output is correct
24 Correct 1022 ms 5564 KB Output is correct
25 Correct 1229 ms 6608 KB Output is correct
26 Correct 1236 ms 6608 KB Output is correct
27 Correct 1320 ms 6608 KB Output is correct
28 Correct 1333 ms 6608 KB Output is correct
29 Correct 1303 ms 6624 KB Output is correct
30 Correct 1049 ms 5564 KB Output is correct
31 Correct 1319 ms 6612 KB Output is correct
32 Correct 1256 ms 6556 KB Output is correct
33 Correct 1037 ms 5564 KB Output is correct
34 Correct 1301 ms 6608 KB Output is correct
35 Correct 1114 ms 6432 KB Output is correct
36 Correct 1034 ms 5564 KB Output is correct
37 Correct 1066 ms 5564 KB Output is correct
38 Correct 2500 ms 6600 KB Output is correct
39 Correct 1246 ms 6608 KB Output is correct
40 Correct 1208 ms 6256 KB Output is correct
41 Correct 1760 ms 6608 KB Output is correct
42 Correct 2611 ms 6608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 411 ms 5484 KB Output is correct
2 Correct 544 ms 5444 KB Output is correct
3 Correct 572 ms 5444 KB Output is correct
4 Correct 508 ms 5444 KB Output is correct
5 Correct 477 ms 5444 KB Output is correct
6 Correct 492 ms 5444 KB Output is correct
7 Correct 414 ms 5444 KB Output is correct
8 Correct 539 ms 5444 KB Output is correct
9 Correct 536 ms 5444 KB Output is correct
10 Correct 536 ms 5444 KB Output is correct
11 Correct 537 ms 5444 KB Output is correct
12 Correct 537 ms 5444 KB Output is correct
13 Correct 540 ms 5444 KB Output is correct
14 Correct 541 ms 5444 KB Output is correct
15 Correct 545 ms 5532 KB Output is correct
16 Correct 543 ms 5444 KB Output is correct
17 Correct 538 ms 5444 KB Output is correct
18 Correct 569 ms 5444 KB Output is correct
19 Correct 557 ms 5456 KB Output is correct
20 Correct 619 ms 5440 KB Output is correct
21 Correct 553 ms 5444 KB Output is correct
22 Correct 363 ms 5444 KB Output is correct
23 Correct 548 ms 5520 KB Output is correct
24 Correct 480 ms 5444 KB Output is correct
25 Correct 552 ms 5444 KB Output is correct
26 Correct 399 ms 5444 KB Output is correct
27 Correct 549 ms 5444 KB Output is correct
28 Correct 465 ms 5444 KB Output is correct
29 Correct 545 ms 5444 KB Output is correct
30 Correct 367 ms 5444 KB Output is correct
31 Correct 577 ms 5440 KB Output is correct
32 Correct 551 ms 5440 KB Output is correct
33 Correct 587 ms 5440 KB Output is correct
34 Correct 424 ms 5568 KB Output is correct
35 Correct 582 ms 5568 KB Output is correct
36 Correct 585 ms 5568 KB Output is correct
37 Correct 671 ms 5440 KB Output is correct
38 Correct 583 ms 5564 KB Output is correct
39 Correct 578 ms 5440 KB Output is correct
40 Correct 586 ms 5440 KB Output is correct
41 Correct 579 ms 5476 KB Output is correct
42 Correct 581 ms 5440 KB Output is correct
43 Correct 472 ms 5440 KB Output is correct
44 Correct 580 ms 5440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 411 ms 5484 KB Output is correct
2 Correct 544 ms 5444 KB Output is correct
3 Correct 572 ms 5444 KB Output is correct
4 Correct 508 ms 5444 KB Output is correct
5 Correct 477 ms 5444 KB Output is correct
6 Correct 492 ms 5444 KB Output is correct
7 Correct 414 ms 5444 KB Output is correct
8 Correct 539 ms 5444 KB Output is correct
9 Correct 536 ms 5444 KB Output is correct
10 Correct 536 ms 5444 KB Output is correct
11 Correct 537 ms 5444 KB Output is correct
12 Correct 537 ms 5444 KB Output is correct
13 Correct 540 ms 5444 KB Output is correct
14 Correct 541 ms 5444 KB Output is correct
15 Correct 545 ms 5532 KB Output is correct
16 Correct 543 ms 5444 KB Output is correct
17 Correct 538 ms 5444 KB Output is correct
18 Correct 569 ms 5444 KB Output is correct
19 Correct 1462 ms 6608 KB Output is correct
20 Correct 2394 ms 6608 KB Output is correct
21 Correct 1160 ms 6588 KB Output is correct
22 Correct 1133 ms 6480 KB Output is correct
23 Correct 1033 ms 5564 KB Output is correct
24 Correct 1022 ms 5564 KB Output is correct
25 Correct 1229 ms 6608 KB Output is correct
26 Correct 1236 ms 6608 KB Output is correct
27 Correct 1320 ms 6608 KB Output is correct
28 Correct 1333 ms 6608 KB Output is correct
29 Correct 1303 ms 6624 KB Output is correct
30 Correct 1049 ms 5564 KB Output is correct
31 Correct 1319 ms 6612 KB Output is correct
32 Correct 1256 ms 6556 KB Output is correct
33 Correct 1037 ms 5564 KB Output is correct
34 Correct 1301 ms 6608 KB Output is correct
35 Correct 1114 ms 6432 KB Output is correct
36 Correct 1034 ms 5564 KB Output is correct
37 Correct 1066 ms 5564 KB Output is correct
38 Correct 2500 ms 6600 KB Output is correct
39 Correct 1246 ms 6608 KB Output is correct
40 Correct 1208 ms 6256 KB Output is correct
41 Correct 1760 ms 6608 KB Output is correct
42 Correct 2611 ms 6608 KB Output is correct
43 Correct 557 ms 5456 KB Output is correct
44 Correct 619 ms 5440 KB Output is correct
45 Correct 553 ms 5444 KB Output is correct
46 Correct 363 ms 5444 KB Output is correct
47 Correct 548 ms 5520 KB Output is correct
48 Correct 480 ms 5444 KB Output is correct
49 Correct 552 ms 5444 KB Output is correct
50 Correct 399 ms 5444 KB Output is correct
51 Correct 549 ms 5444 KB Output is correct
52 Correct 465 ms 5444 KB Output is correct
53 Correct 545 ms 5444 KB Output is correct
54 Correct 367 ms 5444 KB Output is correct
55 Correct 577 ms 5440 KB Output is correct
56 Correct 551 ms 5440 KB Output is correct
57 Correct 587 ms 5440 KB Output is correct
58 Correct 424 ms 5568 KB Output is correct
59 Correct 582 ms 5568 KB Output is correct
60 Correct 585 ms 5568 KB Output is correct
61 Correct 671 ms 5440 KB Output is correct
62 Correct 583 ms 5564 KB Output is correct
63 Correct 578 ms 5440 KB Output is correct
64 Correct 586 ms 5440 KB Output is correct
65 Correct 579 ms 5476 KB Output is correct
66 Correct 581 ms 5440 KB Output is correct
67 Correct 472 ms 5440 KB Output is correct
68 Correct 580 ms 5440 KB Output is correct
69 Correct 2915 ms 8312 KB Output is correct
70 Correct 4321 ms 8776 KB Output is correct
71 Correct 1093 ms 5584 KB Output is correct
72 Correct 1075 ms 5584 KB Output is correct
73 Correct 1081 ms 5584 KB Output is correct
74 Correct 1452 ms 7344 KB Output is correct
75 Correct 1077 ms 5564 KB Output is correct
76 Correct 1676 ms 6972 KB Output is correct
77 Correct 1504 ms 6964 KB Output is correct
78 Correct 1070 ms 5564 KB Output is correct
79 Correct 1069 ms 5564 KB Output is correct
80 Correct 2557 ms 7864 KB Output is correct
81 Correct 1205 ms 5576 KB Output is correct
82 Correct 3273 ms 8748 KB Output is correct
83 Correct 3099 ms 8624 KB Output is correct
84 Correct 1211 ms 5712 KB Output is correct
85 Correct 1183 ms 5576 KB Output is correct
86 Correct 2534 ms 7972 KB Output is correct
87 Correct 3066 ms 8820 KB Output is correct
88 Correct 1212 ms 5692 KB Output is correct
89 Correct 2655 ms 8528 KB Output is correct
90 Correct 3024 ms 8804 KB Output is correct
91 Correct 1202 ms 5676 KB Output is correct
92 Correct 2663 ms 8132 KB Output is correct
93 Correct 1197 ms 5656 KB Output is correct
94 Correct 1202 ms 5612 KB Output is correct
95 Correct 1237 ms 5576 KB Output is correct
96 Correct 2444 ms 6608 KB Output is correct
97 Correct 2841 ms 8832 KB Output is correct
98 Correct 2447 ms 7708 KB Output is correct
99 Correct 2925 ms 8780 KB Output is correct
100 Correct 3830 ms 8780 KB Output is correct