답안 #974079

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
974079 2024-05-02T18:11:41 Z Ooops_sorry 길고양이 (JOI20_stray) C++14
100 / 100
47 ms 16736 KB
#ifndef LOCAL
  #include "Anthony.h"
#endif 
#include<iostream>
#include<deque>
#include<algorithm>
#include<vector>
#include<map>
#include<random>
#include<time.h>
#include<cassert>
#include<chrono>
#include<set>
#include<unordered_set>
#include<array>
 
using namespace std;
 
#define ull unsigned long long
#define pb push_back
#define ll long long
#define all(a) a.begin(), a.end()
#define ld long double 

mt19937_64 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

const int N = 2e4 + 10;
vector<pair<int, int>> g[N];

vector<int> res;

string s = "100110100110", rev_s = "011001011001";

void dfs(int v, int p, int pos) {
  if (v == 0) {
    for (auto [u, i] : g[v]) {
      res[i] = 1;
      dfs(u, v, 1);
    } 
  } else {
    int last = s[pos + 5] - '0';
    if (g[v].size() >= 3) {
      for (auto [u, i] : g[v]) {
        if (u != p) {
          res[i] = last ^ 1;
          dfs(u, v, last ^ 1);
        }
      }
    } else {
      for (auto [u, i] : g[v]) {
        if (u != p) {
          res[i] = s[pos] - '0';
          dfs(u, v, (pos + 1) % 6);
        }
      }
    }
  }
}

vector<int> Mark(int n, int m, int a, int b, vector<int> u, vector<int> v) {
  for (int i = 0; i < m; i++) {
    g[u[i]].pb({v[i], i});
    g[v[i]].pb({u[i], i});
  }
  if (a >= 3) {
    vector<int> d(n, -1);
    d[0] = 0;
    deque<int> q{0};
    while (q.size() > 0) {
      int v = q.front();
      q.pop_front();
      for (auto [u, i] : g[v]) {
        if (d[u] == -1) {
          d[u] = d[v] + 1;
          q.pb(u);
        }
      }
    }
    vector<int> ans(m, -1);
    for (int v = 0; v < n; v++) {
      for (auto [u, i] : g[v]) {
        if (d[u] == d[v]) {
          ans[i] = d[u] % 3;
        } else {
          ans[i] = min(d[u], d[v]) % 3;
        }
      }
    }
    return ans;
  } else {
    res.resize(m, -1);
    dfs(0, -1, -1);
    return res;
  }
}
#ifndef LOCAL
  #include "Catherine.h"
#endif 
#include<iostream>
#include<deque>
#include<algorithm>
#include<vector>
#include<map>
#include<random>
#include<time.h>
#include<cassert>
#include<chrono>
#include<set>
#include<unordered_set>
#include<array>
 
using namespace std;
 
#define ull unsigned long long
#define pb push_back
#define ll long long
#define all(a) a.begin(), a.end()
#define ld long double 

mt19937_64 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

int A, B;

void Init(int A_, int B_) {
  A = A_;
  B = B_;
}

string kek = "";
bool top = 0;
int last = -1;

string s = "100110100110", rev_s = "011001011001";

bool in(string s, string t) {
  for (int i = 0; i + t.size() <= s.size(); i++) {
    if (s.substr(i, (int)t.size()) == t) {
      return 1;
    }
  }
  return 0;
}

int Move(std::vector<int> y) {
  if (A >= 3) {
    for (int i = 0; i < 3; i++) {
      if (y[i] > 0 && y[(i + 1) % 3] > 0) {
        return i;
      }
    }
    for (int i = 0; i < 3; i++) {
      if (y[i] > 0) {
        return i;
      }
    }
  } else {
    vector<int> y_new = y;
    if (last != -1) {
      y_new[last]++;
    }
    if (y_new[0] + y_new[1] > 2) {
      if (y_new[0] == 1) {
        last = 0;
      } else {
        last = 1;
      }
      top = 1;
      if (y[last] == 0) return -1;
      return last;
    }
    if (top) {
      if (y[0] > 0) {
        last = 0;
      } else {
        last = 1;
      }
      return last;
    }
    if (y[0] + y[1] == 2) {
      if (y[0] > 0 && y[1] > 0) {
        kek += "01";
        last = 1;
        return last;
      } else if (y[0] > 0) {
        kek += "00";
        last = 0;
        return last;
      } else {
        kek += "11";
        last = 1;
        return last;
      }
    } else if (y[0] + y[1] == 1) {
      if (y[0] > 0) {
        kek += "0";
      } else {
        kek += "1";
      }
      if (!in(rev_s, kek)) {
        assert(in(s, kek));
        top = 1;
        return -1;
      } else if (!in(s, kek)) {
        assert(in(rev_s, kek));
        top = 1;
        last = kek.back() - '0';
        return last;
      } else {
        last = kek.back() - '0';
        return last;
      }
    } else {
      top = 1;
      return -1;
    }
  }
  assert(0);
}

Compilation message

Anthony.cpp: In function 'void dfs(int, int, int)':
Anthony.cpp:36:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   36 |     for (auto [u, i] : g[v]) {
      |               ^
Anthony.cpp:43:17: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   43 |       for (auto [u, i] : g[v]) {
      |                 ^
Anthony.cpp:50:17: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   50 |       for (auto [u, i] : g[v]) {
      |                 ^
Anthony.cpp: In function 'std::vector<int> Mark(int, int, int, int, std::vector<int>, std::vector<int>)':
Anthony.cpp:72:17: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   72 |       for (auto [u, i] : g[v]) {
      |                 ^
Anthony.cpp:81:17: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   81 |       for (auto [u, i] : g[v]) {
      |                 ^
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 15732 KB Output is correct
2 Correct 1 ms 1804 KB Output is correct
3 Correct 25 ms 14980 KB Output is correct
4 Correct 34 ms 16736 KB Output is correct
5 Correct 36 ms 16452 KB Output is correct
6 Correct 26 ms 15524 KB Output is correct
7 Correct 27 ms 15472 KB Output is correct
8 Correct 32 ms 16064 KB Output is correct
9 Correct 31 ms 16560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 15732 KB Output is correct
2 Correct 1 ms 1804 KB Output is correct
3 Correct 25 ms 14980 KB Output is correct
4 Correct 34 ms 16736 KB Output is correct
5 Correct 36 ms 16452 KB Output is correct
6 Correct 26 ms 15524 KB Output is correct
7 Correct 27 ms 15472 KB Output is correct
8 Correct 32 ms 16064 KB Output is correct
9 Correct 31 ms 16560 KB Output is correct
10 Correct 27 ms 13708 KB Output is correct
11 Correct 26 ms 13684 KB Output is correct
12 Correct 28 ms 13656 KB Output is correct
13 Correct 26 ms 13424 KB Output is correct
14 Correct 26 ms 13936 KB Output is correct
15 Correct 28 ms 14188 KB Output is correct
16 Correct 34 ms 16160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 13188 KB Output is correct
2 Correct 0 ms 1308 KB Output is correct
3 Correct 22 ms 12676 KB Output is correct
4 Correct 31 ms 14428 KB Output is correct
5 Correct 32 ms 14384 KB Output is correct
6 Correct 26 ms 13348 KB Output is correct
7 Correct 26 ms 13168 KB Output is correct
8 Correct 38 ms 13916 KB Output is correct
9 Correct 33 ms 13912 KB Output is correct
10 Correct 27 ms 13932 KB Output is correct
11 Correct 28 ms 13556 KB Output is correct
12 Correct 27 ms 13692 KB Output is correct
13 Correct 27 ms 13952 KB Output is correct
14 Correct 33 ms 13808 KB Output is correct
15 Correct 30 ms 13916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 13188 KB Output is correct
2 Correct 0 ms 1308 KB Output is correct
3 Correct 22 ms 12676 KB Output is correct
4 Correct 31 ms 14428 KB Output is correct
5 Correct 32 ms 14384 KB Output is correct
6 Correct 26 ms 13348 KB Output is correct
7 Correct 26 ms 13168 KB Output is correct
8 Correct 38 ms 13916 KB Output is correct
9 Correct 33 ms 13912 KB Output is correct
10 Correct 27 ms 13932 KB Output is correct
11 Correct 28 ms 13556 KB Output is correct
12 Correct 27 ms 13692 KB Output is correct
13 Correct 27 ms 13952 KB Output is correct
14 Correct 33 ms 13808 KB Output is correct
15 Correct 30 ms 13916 KB Output is correct
16 Correct 25 ms 11744 KB Output is correct
17 Correct 24 ms 11636 KB Output is correct
18 Correct 24 ms 11628 KB Output is correct
19 Correct 24 ms 11644 KB Output is correct
20 Correct 26 ms 12392 KB Output is correct
21 Correct 27 ms 12116 KB Output is correct
22 Correct 28 ms 13740 KB Output is correct
23 Correct 24 ms 11872 KB Output is correct
24 Correct 25 ms 11756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1568 KB Output is correct
2 Correct 1 ms 1292 KB Output is correct
3 Correct 1 ms 1572 KB Output is correct
4 Correct 2 ms 1568 KB Output is correct
5 Correct 2 ms 1564 KB Output is correct
6 Correct 2 ms 1564 KB Output is correct
7 Correct 2 ms 1572 KB Output is correct
8 Correct 2 ms 1564 KB Output is correct
9 Correct 2 ms 1572 KB Output is correct
10 Correct 2 ms 1572 KB Output is correct
11 Correct 2 ms 1564 KB Output is correct
12 Correct 2 ms 1824 KB Output is correct
13 Correct 1 ms 1824 KB Output is correct
14 Correct 2 ms 1568 KB Output is correct
15 Correct 2 ms 1564 KB Output is correct
16 Correct 2 ms 1568 KB Output is correct
17 Correct 2 ms 1564 KB Output is correct
18 Correct 2 ms 1572 KB Output is correct
19 Correct 2 ms 1564 KB Output is correct
20 Correct 1 ms 1564 KB Output is correct
21 Correct 2 ms 1572 KB Output is correct
22 Correct 2 ms 1572 KB Output is correct
23 Correct 2 ms 1568 KB Output is correct
24 Correct 2 ms 1564 KB Output is correct
25 Correct 2 ms 1564 KB Output is correct
26 Correct 2 ms 1556 KB Output is correct
27 Correct 2 ms 1572 KB Output is correct
28 Correct 1 ms 1560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 11264 KB Output is correct
2 Correct 26 ms 12524 KB Output is correct
3 Correct 1 ms 1300 KB Output is correct
4 Correct 25 ms 11480 KB Output is correct
5 Correct 32 ms 14172 KB Output is correct
6 Correct 32 ms 14104 KB Output is correct
7 Correct 27 ms 13140 KB Output is correct
8 Correct 26 ms 13140 KB Output is correct
9 Correct 47 ms 13912 KB Output is correct
10 Correct 32 ms 14132 KB Output is correct
11 Correct 31 ms 14180 KB Output is correct
12 Correct 30 ms 14176 KB Output is correct
13 Correct 31 ms 14216 KB Output is correct
14 Correct 34 ms 14200 KB Output is correct
15 Correct 32 ms 14080 KB Output is correct
16 Correct 31 ms 14076 KB Output is correct
17 Correct 28 ms 13912 KB Output is correct
18 Correct 28 ms 13900 KB Output is correct
19 Correct 30 ms 13864 KB Output is correct
20 Correct 30 ms 13860 KB Output is correct
21 Correct 37 ms 13792 KB Output is correct
22 Correct 28 ms 13772 KB Output is correct
23 Correct 24 ms 11772 KB Output is correct
24 Correct 31 ms 11900 KB Output is correct
25 Correct 25 ms 12360 KB Output is correct
26 Correct 25 ms 12628 KB Output is correct
27 Correct 26 ms 12936 KB Output is correct
28 Correct 28 ms 12760 KB Output is correct
29 Correct 27 ms 12852 KB Output is correct
30 Correct 28 ms 12852 KB Output is correct
31 Correct 24 ms 11864 KB Output is correct
32 Correct 24 ms 11848 KB Output is correct
33 Correct 26 ms 12368 KB Output is correct
34 Correct 24 ms 12320 KB Output is correct
35 Correct 26 ms 12920 KB Output is correct
36 Correct 26 ms 12876 KB Output is correct
37 Correct 26 ms 12856 KB Output is correct
38 Correct 27 ms 12876 KB Output is correct
39 Correct 27 ms 12920 KB Output is correct
40 Correct 26 ms 12876 KB Output is correct
41 Correct 30 ms 13380 KB Output is correct
42 Correct 28 ms 13644 KB Output is correct
43 Correct 27 ms 13396 KB Output is correct
44 Correct 27 ms 13364 KB Output is correct
45 Correct 28 ms 13396 KB Output is correct
46 Correct 28 ms 13392 KB Output is correct
47 Correct 26 ms 12888 KB Output is correct
48 Correct 26 ms 12872 KB Output is correct
49 Correct 26 ms 12780 KB Output is correct
50 Correct 31 ms 12972 KB Output is correct
51 Correct 26 ms 11908 KB Output is correct
52 Correct 26 ms 11868 KB Output is correct
53 Correct 24 ms 11852 KB Output is correct
54 Correct 24 ms 11924 KB Output is correct
55 Correct 25 ms 12008 KB Output is correct
56 Correct 25 ms 11848 KB Output is correct
57 Correct 24 ms 11860 KB Output is correct
58 Correct 25 ms 11860 KB Output is correct
59 Correct 24 ms 11860 KB Output is correct
60 Correct 27 ms 11976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 11368 KB Output is correct
2 Correct 31 ms 12628 KB Output is correct
3 Correct 1 ms 1564 KB Output is correct
4 Correct 20 ms 11684 KB Output is correct
5 Correct 31 ms 14236 KB Output is correct
6 Correct 33 ms 14100 KB Output is correct
7 Correct 27 ms 13172 KB Output is correct
8 Correct 26 ms 13144 KB Output is correct
9 Correct 31 ms 14168 KB Output is correct
10 Correct 34 ms 14096 KB Output is correct
11 Correct 30 ms 14280 KB Output is correct
12 Correct 37 ms 14156 KB Output is correct
13 Correct 31 ms 13984 KB Output is correct
14 Correct 31 ms 14192 KB Output is correct
15 Correct 31 ms 14076 KB Output is correct
16 Correct 30 ms 14156 KB Output is correct
17 Correct 28 ms 13976 KB Output is correct
18 Correct 28 ms 13820 KB Output is correct
19 Correct 31 ms 13788 KB Output is correct
20 Correct 28 ms 13848 KB Output is correct
21 Correct 28 ms 13968 KB Output is correct
22 Correct 35 ms 13964 KB Output is correct
23 Correct 26 ms 11760 KB Output is correct
24 Correct 24 ms 11856 KB Output is correct
25 Correct 25 ms 12144 KB Output is correct
26 Correct 25 ms 12372 KB Output is correct
27 Correct 27 ms 12948 KB Output is correct
28 Correct 27 ms 12876 KB Output is correct
29 Correct 26 ms 12872 KB Output is correct
30 Correct 26 ms 12824 KB Output is correct
31 Correct 27 ms 11856 KB Output is correct
32 Correct 26 ms 11872 KB Output is correct
33 Correct 26 ms 12268 KB Output is correct
34 Correct 25 ms 12372 KB Output is correct
35 Correct 26 ms 12888 KB Output is correct
36 Correct 26 ms 12904 KB Output is correct
37 Correct 26 ms 12800 KB Output is correct
38 Correct 27 ms 12928 KB Output is correct
39 Correct 26 ms 12960 KB Output is correct
40 Correct 26 ms 12876 KB Output is correct
41 Correct 28 ms 13312 KB Output is correct
42 Correct 33 ms 13320 KB Output is correct
43 Correct 27 ms 13344 KB Output is correct
44 Correct 28 ms 13388 KB Output is correct
45 Correct 28 ms 13404 KB Output is correct
46 Correct 27 ms 13460 KB Output is correct
47 Correct 27 ms 12696 KB Output is correct
48 Correct 26 ms 12880 KB Output is correct
49 Correct 25 ms 12628 KB Output is correct
50 Correct 26 ms 13136 KB Output is correct
51 Correct 27 ms 11936 KB Output is correct
52 Correct 31 ms 11868 KB Output is correct
53 Correct 24 ms 11856 KB Output is correct
54 Correct 24 ms 11856 KB Output is correct
55 Correct 24 ms 11852 KB Output is correct
56 Correct 26 ms 11868 KB Output is correct
57 Correct 27 ms 11868 KB Output is correct
58 Correct 24 ms 12108 KB Output is correct
59 Correct 26 ms 11852 KB Output is correct
60 Correct 25 ms 11864 KB Output is correct