답안 #923268

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
923268 2024-02-07T04:22:35 Z huutuan 길고양이 (JOI20_stray) C++14
100 / 100
45 ms 17276 KB
#include "Anthony.h"
#include <bits/stdc++.h>

using namespace std;

#ifndef sus
#define cerr if (0) cerr
#endif

const int N=2e4+10;

namespace sub1234{
   vector<int> g[N];
   vector<int> ans;
   int dep[N];
   void bfs(){
      memset(dep, -1, sizeof dep);
      queue<int> q;
      q.push(0); dep[0]=0;
      while (q.size()){
         int u=q.front(); q.pop();
         for (int v:g[u]){
            if (dep[v]==-1){
               dep[v]=dep[u]+1;
               q.push(v);
            }
         }
      }
   }
   vector<int> solve(int n, int m, vector<int> u, vector<int> v){
      ans.resize(m, -1);
      for (int i=0; i<m; ++i){
         g[u[i]].push_back(v[i]);
         g[v[i]].push_back(u[i]);
      }
      bfs();
      for (int i=0; i<m; ++i){
         ans[i]=min(dep[u[i]], dep[v[i]])%3;
         cerr << u[i] << ' ' << v[i] << ' ' << ans[i] << '\n';
      }
      return ans;
   }
}

namespace sub567{
   string sussy="011001";
   vector<int> path;
   vector<pair<int, int>> g[N];
   vector<int> ans;
   int par_idx[N];
   void dfs(int u, int p){
      pair<int, int> pp={-1, -1};
      for (auto &e:g[u]) if (e.first==p) pp=e;
      if (pp.first!=-1) g[u].erase(find(g[u].begin(), g[u].end(), pp));
      if ((int)g[u].size()==1){
         if (path.empty()) path.push_back(par_idx[u]);
         path.push_back(g[u][0].second);
         par_idx[g[u][0].first]=g[u][0].second;
         dfs(g[u][0].first, u);
      }else{
         if (path.size()){
            int first_edge=path[0]==-1?0:ans[path[0]]^1;
            path.erase(path.begin());
            for (int i=0; i<(int)path.size(); ++i) ans[path[i]]=sussy[(i+first_edge)%6]-'0';
         }
         path.clear();
         for (auto &e:g[u]){
            int v=e.first, i=e.second;
            ans[i]=par_idx[u]==-1?0:ans[par_idx[u]]^1;
            par_idx[v]=i;
            if ((int)g[v].size()==1){
               path.clear();
               path.push_back(par_idx[u]);
            }
            dfs(v, u);
         }
      }
   }
   vector<int> solve(int n, int m, vector<int> u, vector<int> v){
      ans.resize(m);
      par_idx[0]=-1;
      for (int i=0; i<m; ++i){
         g[u[i]].emplace_back(v[i], i);
         g[v[i]].emplace_back(u[i], i);
      }
      dfs(0, -1);
      for (int i=0; i<m; ++i) cerr << u[i] << ' ' << v[i] << ' ' << ans[i] << '\n';
      return ans;
   }
}

vector<int> Mark(int n, int m, int a, int b,
                 vector<int> u, vector<int> v) {
   if (a!=2){
      return sub1234::solve(n, m, u, v);
   }
   return sub567::solve(n, m, u, v);
}
#include "Catherine.h"
#include <bits/stdc++.h>

using namespace std;

#ifndef sus
#define cerr if (0) cerr
#endif

int a, b;

void Init(int A, int B) {
   a=A;
   b=B;
}

vector<pair<int, int>> v;

string sussy="011001";

bool check_sus(){
   if ((int)v.size()<5) return 0;
   string lmao;
   for (int i=5; i>=1; --i){
      if (v.end()[-i].first!=1) return 0;
      lmao.push_back('0'+v.end()[-i].second);
   }
   cerr << "check " << lmao << endl;
   if ((sussy+sussy).find(lmao)!=string::npos){
      cerr << "sus " << lmao << endl;
      return 1;
   }
   return 0;
}

int Move(vector<int> y) {
   if (a!=2){
      if (y[0] && y[1]) return 0;
      if (y[1] && y[2]) return 1;
      if (y[2] && y[0]) return 2;
      for (int i=0; i<3; ++i) if (y[i]) return i;
   }
   if (y[0]+y[1]==1){
      if (y[0]){
         v.emplace_back(1, 0);
         if (check_sus()){
            v.emplace_back(-1, v.back().second);
            return -1;
         }
         return 0;
      }else{
         v.emplace_back(1, 1);
         if (check_sus()){
            v.emplace_back(-1, v.back().second);
            return -1;
         }
         return 1;
      }
   }
   if (v.size()){
      int lst=v.back().second;
      if (y[lst^1]==1){
         v.emplace_back(0, lst^1);
         return lst^1;
      }
      v.emplace_back(-1, lst);
      return -1;
   }
   if (y[0]==1 && y[1]==1){
      v.emplace_back(1, 0);
      v.emplace_back(1, 1);
      return 1;
   }
   if (y[0]==2){
      v.emplace_back(1, 0);
      v.emplace_back(1, 0);
      return 0;
   }
   if (y[1]==2){
      v.emplace_back(1, 1);
      v.emplace_back(1, 1);
      return 1;
   }
   if (y[1]==1){
      v.emplace_back(y[0]<=1, 1);
      return 1;
   }
   if (y[0]==1){
      v.emplace_back(y[1]<=1, 0);
      return 0;
   }
   if (y[1]){
      v.emplace_back(0, 1);
      return 1;
   }
   if (y[0]){
      v.emplace_back(0, 0);
      return 0;
   }
   return -1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 16216 KB Output is correct
2 Correct 1 ms 1808 KB Output is correct
3 Correct 26 ms 16080 KB Output is correct
4 Correct 34 ms 17276 KB Output is correct
5 Correct 39 ms 17200 KB Output is correct
6 Correct 30 ms 16044 KB Output is correct
7 Correct 30 ms 16064 KB Output is correct
8 Correct 41 ms 16604 KB Output is correct
9 Correct 40 ms 17004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 16216 KB Output is correct
2 Correct 1 ms 1808 KB Output is correct
3 Correct 26 ms 16080 KB Output is correct
4 Correct 34 ms 17276 KB Output is correct
5 Correct 39 ms 17200 KB Output is correct
6 Correct 30 ms 16044 KB Output is correct
7 Correct 30 ms 16064 KB Output is correct
8 Correct 41 ms 16604 KB Output is correct
9 Correct 40 ms 17004 KB Output is correct
10 Correct 32 ms 14248 KB Output is correct
11 Correct 26 ms 14176 KB Output is correct
12 Correct 26 ms 14200 KB Output is correct
13 Correct 26 ms 14188 KB Output is correct
14 Correct 26 ms 14460 KB Output is correct
15 Correct 30 ms 14924 KB Output is correct
16 Correct 32 ms 16772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 13632 KB Output is correct
2 Correct 1 ms 1800 KB Output is correct
3 Correct 25 ms 13416 KB Output is correct
4 Correct 33 ms 15132 KB Output is correct
5 Correct 45 ms 15136 KB Output is correct
6 Correct 34 ms 13684 KB Output is correct
7 Correct 26 ms 13676 KB Output is correct
8 Correct 32 ms 14456 KB Output is correct
9 Correct 30 ms 14452 KB Output is correct
10 Correct 30 ms 14200 KB Output is correct
11 Correct 30 ms 14092 KB Output is correct
12 Correct 37 ms 14180 KB Output is correct
13 Correct 27 ms 14188 KB Output is correct
14 Correct 30 ms 14448 KB Output is correct
15 Correct 41 ms 14416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 13632 KB Output is correct
2 Correct 1 ms 1800 KB Output is correct
3 Correct 25 ms 13416 KB Output is correct
4 Correct 33 ms 15132 KB Output is correct
5 Correct 45 ms 15136 KB Output is correct
6 Correct 34 ms 13684 KB Output is correct
7 Correct 26 ms 13676 KB Output is correct
8 Correct 32 ms 14456 KB Output is correct
9 Correct 30 ms 14452 KB Output is correct
10 Correct 30 ms 14200 KB Output is correct
11 Correct 30 ms 14092 KB Output is correct
12 Correct 37 ms 14180 KB Output is correct
13 Correct 27 ms 14188 KB Output is correct
14 Correct 30 ms 14448 KB Output is correct
15 Correct 41 ms 14416 KB Output is correct
16 Correct 24 ms 12412 KB Output is correct
17 Correct 25 ms 12284 KB Output is correct
18 Correct 33 ms 12396 KB Output is correct
19 Correct 25 ms 12144 KB Output is correct
20 Correct 26 ms 13104 KB Output is correct
21 Correct 26 ms 12640 KB Output is correct
22 Correct 34 ms 14528 KB Output is correct
23 Correct 26 ms 12336 KB Output is correct
24 Correct 26 ms 12184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2072 KB Output is correct
2 Correct 1 ms 1816 KB Output is correct
3 Correct 3 ms 2080 KB Output is correct
4 Correct 2 ms 2072 KB Output is correct
5 Correct 2 ms 2320 KB Output is correct
6 Correct 2 ms 2064 KB Output is correct
7 Correct 2 ms 2072 KB Output is correct
8 Correct 2 ms 2064 KB Output is correct
9 Correct 2 ms 2064 KB Output is correct
10 Correct 2 ms 2080 KB Output is correct
11 Correct 2 ms 2072 KB Output is correct
12 Correct 2 ms 2080 KB Output is correct
13 Correct 2 ms 2064 KB Output is correct
14 Correct 2 ms 2072 KB Output is correct
15 Correct 2 ms 2080 KB Output is correct
16 Correct 2 ms 2076 KB Output is correct
17 Correct 2 ms 2072 KB Output is correct
18 Correct 2 ms 2080 KB Output is correct
19 Correct 2 ms 2072 KB Output is correct
20 Correct 2 ms 2072 KB Output is correct
21 Correct 2 ms 2068 KB Output is correct
22 Correct 2 ms 2080 KB Output is correct
23 Correct 2 ms 2072 KB Output is correct
24 Correct 2 ms 2080 KB Output is correct
25 Correct 2 ms 2080 KB Output is correct
26 Correct 2 ms 2080 KB Output is correct
27 Correct 1 ms 2080 KB Output is correct
28 Correct 2 ms 2080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 12380 KB Output is correct
2 Correct 28 ms 12928 KB Output is correct
3 Correct 1 ms 1804 KB Output is correct
4 Correct 23 ms 11904 KB Output is correct
5 Correct 33 ms 13608 KB Output is correct
6 Correct 40 ms 13704 KB Output is correct
7 Correct 26 ms 12404 KB Output is correct
8 Correct 26 ms 12556 KB Output is correct
9 Correct 36 ms 13552 KB Output is correct
10 Correct 35 ms 13580 KB Output is correct
11 Correct 36 ms 13492 KB Output is correct
12 Correct 32 ms 13440 KB Output is correct
13 Correct 34 ms 13456 KB Output is correct
14 Correct 34 ms 13384 KB Output is correct
15 Correct 33 ms 13436 KB Output is correct
16 Correct 33 ms 13704 KB Output is correct
17 Correct 30 ms 13272 KB Output is correct
18 Correct 36 ms 13204 KB Output is correct
19 Correct 35 ms 13168 KB Output is correct
20 Correct 31 ms 13300 KB Output is correct
21 Correct 31 ms 13184 KB Output is correct
22 Correct 30 ms 13196 KB Output is correct
23 Correct 25 ms 12148 KB Output is correct
24 Correct 26 ms 12076 KB Output is correct
25 Correct 28 ms 12408 KB Output is correct
26 Correct 30 ms 12412 KB Output is correct
27 Correct 28 ms 13160 KB Output is correct
28 Correct 34 ms 13140 KB Output is correct
29 Correct 31 ms 13216 KB Output is correct
30 Correct 31 ms 13108 KB Output is correct
31 Correct 26 ms 12236 KB Output is correct
32 Correct 30 ms 12228 KB Output is correct
33 Correct 27 ms 12484 KB Output is correct
34 Correct 26 ms 12412 KB Output is correct
35 Correct 28 ms 13180 KB Output is correct
36 Correct 27 ms 13172 KB Output is correct
37 Correct 28 ms 13176 KB Output is correct
38 Correct 31 ms 13120 KB Output is correct
39 Correct 28 ms 13176 KB Output is correct
40 Correct 28 ms 13180 KB Output is correct
41 Correct 30 ms 13164 KB Output is correct
42 Correct 30 ms 13164 KB Output is correct
43 Correct 33 ms 13092 KB Output is correct
44 Correct 34 ms 13264 KB Output is correct
45 Correct 31 ms 13156 KB Output is correct
46 Correct 32 ms 13212 KB Output is correct
47 Correct 28 ms 12652 KB Output is correct
48 Correct 28 ms 12712 KB Output is correct
49 Correct 27 ms 12396 KB Output is correct
50 Correct 34 ms 12576 KB Output is correct
51 Correct 29 ms 12152 KB Output is correct
52 Correct 25 ms 12144 KB Output is correct
53 Correct 26 ms 12084 KB Output is correct
54 Correct 25 ms 12156 KB Output is correct
55 Correct 26 ms 12144 KB Output is correct
56 Correct 27 ms 12164 KB Output is correct
57 Correct 26 ms 12164 KB Output is correct
58 Correct 26 ms 12144 KB Output is correct
59 Correct 31 ms 12132 KB Output is correct
60 Correct 25 ms 12148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 12056 KB Output is correct
2 Correct 27 ms 12912 KB Output is correct
3 Correct 1 ms 1820 KB Output is correct
4 Correct 22 ms 11904 KB Output is correct
5 Correct 34 ms 13580 KB Output is correct
6 Correct 36 ms 13516 KB Output is correct
7 Correct 28 ms 12444 KB Output is correct
8 Correct 27 ms 12424 KB Output is correct
9 Correct 34 ms 13956 KB Output is correct
10 Correct 34 ms 13948 KB Output is correct
11 Correct 34 ms 13908 KB Output is correct
12 Correct 33 ms 13908 KB Output is correct
13 Correct 36 ms 13836 KB Output is correct
14 Correct 33 ms 14164 KB Output is correct
15 Correct 33 ms 13908 KB Output is correct
16 Correct 34 ms 13904 KB Output is correct
17 Correct 31 ms 13652 KB Output is correct
18 Correct 31 ms 13728 KB Output is correct
19 Correct 30 ms 13628 KB Output is correct
20 Correct 31 ms 13628 KB Output is correct
21 Correct 31 ms 13736 KB Output is correct
22 Correct 30 ms 13660 KB Output is correct
23 Correct 26 ms 12588 KB Output is correct
24 Correct 26 ms 12616 KB Output is correct
25 Correct 28 ms 12800 KB Output is correct
26 Correct 26 ms 12888 KB Output is correct
27 Correct 30 ms 13392 KB Output is correct
28 Correct 28 ms 13396 KB Output is correct
29 Correct 30 ms 13656 KB Output is correct
30 Correct 31 ms 13548 KB Output is correct
31 Correct 31 ms 12628 KB Output is correct
32 Correct 33 ms 12508 KB Output is correct
33 Correct 28 ms 12884 KB Output is correct
34 Correct 27 ms 12952 KB Output is correct
35 Correct 27 ms 13400 KB Output is correct
36 Correct 27 ms 13652 KB Output is correct
37 Correct 28 ms 13620 KB Output is correct
38 Correct 31 ms 13388 KB Output is correct
39 Correct 27 ms 13136 KB Output is correct
40 Correct 33 ms 13640 KB Output is correct
41 Correct 30 ms 14140 KB Output is correct
42 Correct 31 ms 13616 KB Output is correct
43 Correct 30 ms 13640 KB Output is correct
44 Correct 30 ms 13656 KB Output is correct
45 Correct 31 ms 13608 KB Output is correct
46 Correct 30 ms 13648 KB Output is correct
47 Correct 27 ms 13128 KB Output is correct
48 Correct 31 ms 13104 KB Output is correct
49 Correct 27 ms 13128 KB Output is correct
50 Correct 28 ms 13164 KB Output is correct
51 Correct 26 ms 12620 KB Output is correct
52 Correct 25 ms 12624 KB Output is correct
53 Correct 25 ms 12568 KB Output is correct
54 Correct 30 ms 12920 KB Output is correct
55 Correct 25 ms 12624 KB Output is correct
56 Correct 26 ms 12540 KB Output is correct
57 Correct 28 ms 12624 KB Output is correct
58 Correct 27 ms 12616 KB Output is correct
59 Correct 26 ms 12632 KB Output is correct
60 Correct 29 ms 12608 KB Output is correct