Submission #167313

# Submission time Handle Problem Language Result Execution time Memory
167313 2019-12-07T09:33:58 Z theStaticMind Tenis (COI19_tenis) C++14
51 / 100
500 ms 20820 KB
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define INF 100000000000000000
#define modulo 1000000007
#define mod 998244353
#define int long long int
using namespace std;
vector<vector<int>> data(3,vector<int>(100005));
vector<vector<int>> arr(3);
vector<vector<int>> adj(100005,vector<int>(3,0));
vector<vector<int>> radj(100005,vector<int>(3,0));
vector<bool>vis(100005,false);
vector<bool>win(100005,false);
void dfs(int x){
      vis[x]=true;
      for(int i=0;i<3;i++){
            int y=adj[x][i];
            if(vis[y])continue;
            dfs(y);
      }
}
void rdfs(int x){
      win[x]=true;
      for(int i=0;i<3;i++){
            int y=radj[x][i];
            if(win[y])continue;
            rdfs(y);
      }
}
int32_t main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
   //   freopen("q.gir","r",stdin);
   //   freopen("q.cik","w",stdout);
      int n,q;
      cin>>n>>q;
      for(int k=0;k<3;k++){
            for(int i=0;i<n;i++){
                  int x;
                  cin>>x;
                  arr[k].pb(x);
                  data[k][x]=i;
            }
            arr[k].pb(0);
      }
      for(int k=0;k<3;k++)
      for(int i=0;i<n;i++){
            int x=arr[k][i];
            adj[x][k]=arr[k][i+1];
      }
      for(int k=0;k<3;k++)
      for(int i=1;i<n;i++){
            int x=arr[k][i];
            radj[x][k]=arr[k][i-1];
      }
      for(int i=0;i<3;i++){
            rdfs(arr[i][0]);
      }
      bool task4=true;
      while(q--){
            int k;
            cin>>k;
            if(k==1){
                  int x;
                  cin>>x;
                  if(task4){
                        if(win[x])cout<<"DA\n";
                        else cout<<"NE\n";
                        continue;
                  }
                  for(int i=1;i<=n;i++)vis[i]=false;
                  bool yes=true;
                  dfs(x);
                  for(int i=1;i<=n;i++)yes=(yes&vis[i]);
                  if(yes)cout<<"DA\n";
                  else cout<<"NE\n";
            }
            else{
                  task4=false;
                  int p,x,y;
                  cin>>p>>x>>y;p--;
                  swap(arr[p][data[p][x]],arr[p][data[p][y]]);
                  swap(data[p][x],data[p][y]);
                  int X=data[p][x];
                  int Y=data[p][y];
                  adj[x][p]=arr[p][X+1];
                  adj[y][p]=arr[p][Y+1];
                  if(X>0){
                        adj[arr[p][X-1]][p]=x;
                  }
                  if(Y>0){
                        adj[arr[p][Y-1]][p]=y;
                  }
            }
      }

}
# Verdict Execution time Memory Grader output
1 Correct 23 ms 13672 KB Output is correct
2 Correct 23 ms 13800 KB Output is correct
3 Correct 23 ms 13668 KB Output is correct
4 Correct 23 ms 13668 KB Output is correct
5 Correct 24 ms 13672 KB Output is correct
6 Correct 23 ms 13672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 13672 KB Output is correct
2 Correct 23 ms 13800 KB Output is correct
3 Correct 23 ms 13668 KB Output is correct
4 Correct 23 ms 13668 KB Output is correct
5 Correct 24 ms 13672 KB Output is correct
6 Correct 23 ms 13672 KB Output is correct
7 Correct 26 ms 13668 KB Output is correct
8 Correct 27 ms 13664 KB Output is correct
9 Correct 26 ms 13800 KB Output is correct
10 Correct 26 ms 13712 KB Output is correct
11 Correct 27 ms 13796 KB Output is correct
12 Correct 26 ms 13668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 13672 KB Output is correct
2 Correct 23 ms 13800 KB Output is correct
3 Correct 23 ms 13668 KB Output is correct
4 Correct 23 ms 13668 KB Output is correct
5 Correct 24 ms 13672 KB Output is correct
6 Correct 23 ms 13672 KB Output is correct
7 Correct 26 ms 13668 KB Output is correct
8 Correct 27 ms 13664 KB Output is correct
9 Correct 26 ms 13800 KB Output is correct
10 Correct 26 ms 13712 KB Output is correct
11 Correct 27 ms 13796 KB Output is correct
12 Correct 26 ms 13668 KB Output is correct
13 Correct 138 ms 18332 KB Output is correct
14 Correct 135 ms 18384 KB Output is correct
15 Correct 143 ms 19940 KB Output is correct
16 Correct 141 ms 19688 KB Output is correct
17 Correct 147 ms 20212 KB Output is correct
18 Correct 146 ms 20200 KB Output is correct
19 Correct 165 ms 20184 KB Output is correct
20 Correct 98 ms 17352 KB Output is correct
21 Correct 161 ms 20200 KB Output is correct
22 Correct 167 ms 20072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 127 ms 18280 KB Output is correct
2 Correct 120 ms 19916 KB Output is correct
3 Correct 124 ms 19940 KB Output is correct
4 Correct 117 ms 19916 KB Output is correct
5 Correct 119 ms 19816 KB Output is correct
6 Correct 119 ms 20072 KB Output is correct
7 Correct 116 ms 20024 KB Output is correct
8 Correct 120 ms 19916 KB Output is correct
9 Correct 196 ms 19940 KB Output is correct
10 Correct 115 ms 19944 KB Output is correct
11 Correct 122 ms 20296 KB Output is correct
12 Correct 113 ms 19816 KB Output is correct
13 Correct 123 ms 19924 KB Output is correct
14 Correct 117 ms 19940 KB Output is correct
15 Correct 121 ms 19876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 13672 KB Output is correct
2 Correct 23 ms 13800 KB Output is correct
3 Correct 23 ms 13668 KB Output is correct
4 Correct 23 ms 13668 KB Output is correct
5 Correct 24 ms 13672 KB Output is correct
6 Correct 23 ms 13672 KB Output is correct
7 Correct 26 ms 13668 KB Output is correct
8 Correct 27 ms 13664 KB Output is correct
9 Correct 26 ms 13800 KB Output is correct
10 Correct 26 ms 13712 KB Output is correct
11 Correct 27 ms 13796 KB Output is correct
12 Correct 26 ms 13668 KB Output is correct
13 Correct 138 ms 18332 KB Output is correct
14 Correct 135 ms 18384 KB Output is correct
15 Correct 143 ms 19940 KB Output is correct
16 Correct 141 ms 19688 KB Output is correct
17 Correct 147 ms 20212 KB Output is correct
18 Correct 146 ms 20200 KB Output is correct
19 Correct 165 ms 20184 KB Output is correct
20 Correct 98 ms 17352 KB Output is correct
21 Correct 161 ms 20200 KB Output is correct
22 Correct 167 ms 20072 KB Output is correct
23 Correct 127 ms 18280 KB Output is correct
24 Correct 120 ms 19916 KB Output is correct
25 Correct 124 ms 19940 KB Output is correct
26 Correct 117 ms 19916 KB Output is correct
27 Correct 119 ms 19816 KB Output is correct
28 Correct 119 ms 20072 KB Output is correct
29 Correct 116 ms 20024 KB Output is correct
30 Correct 120 ms 19916 KB Output is correct
31 Correct 196 ms 19940 KB Output is correct
32 Correct 115 ms 19944 KB Output is correct
33 Correct 122 ms 20296 KB Output is correct
34 Correct 113 ms 19816 KB Output is correct
35 Correct 123 ms 19924 KB Output is correct
36 Correct 117 ms 19940 KB Output is correct
37 Correct 121 ms 19876 KB Output is correct
38 Execution timed out 1050 ms 20820 KB Time limit exceeded
39 Halted 0 ms 0 KB -