Submission #993745

# Submission time Handle Problem Language Result Execution time Memory
993745 2024-06-06T11:00:10 Z prvocislo Stray Cat (JOI20_stray) C++17
85 / 100
52 ms 15696 KB
// .. And I love you, it's ruining my life

#include "Anthony.h"
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <vector>
typedef long long ll;
typedef long double ld;
using namespace std;

namespace 
{
    const int d[6] = { 0, 0, 1, 0, 1, 1 };
    vector<vector<pair<int, int> > > g;
    vector<int> col;
    void dfs2(int u, int p = -1, int c = 1, int i = -1)
    {
        if (!u || g[u].size() != 2)
        {
            for (pair<int, int> v : g[u]) if (v.first != p)
            {
                col[v.second] = c ^ 1;
                dfs2(v.first, u, (c ^ 1));
            }
        }
        else
        {
            if (i == -1) i = (c ? 2 : 0);
            for (pair<int, int> v : g[u]) if (v.first != p)
            {
                col[v.second] = d[(i + 1) % 6];
                dfs2(v.first, u, d[(i + 1) % 6], (i + 1) % 6);
            }
        }
    }
    void bfs3()
    {
        vector<int> d(g.size(), -1);
        d[0] = 0;
        queue<int> q;
        q.push(0);
        while (!q.empty())
        {
            int u = q.front();
            q.pop();
            for (pair<int, int> v : g[u])
            {
                if (d[v.first] == -1)
                {
                    q.push(v.first);
                    d[v.first] = d[u] + 1;
                }
                col[v.second] = min(d[v.first], d[u]) % 3;
            }
        }
    }
}

vector<int> Mark(int n, int m, int a, int b, vector<int> u, vector<int> v) 
{
    col.assign(m, -1), g.assign(n, {});
    for (int i = 0; i < m; i++) g[u[i]].push_back({ v[i], i }), g[v[i]].push_back({ u[i], i });
    if (a == 2)
    {
        ::dfs2(0);
        return col;
    }
    else
    {
        ::bfs3();
        return col;
    }
}
// All my mornings are Mondays stuck in an endless February...
// I took the miracle move-on drug, the effects were temporary

#include "Catherine.h"
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <vector>
typedef long long ll;
typedef long double ld;
using namespace std;

namespace 
{
    const int d[6] = { 0, 0, 1, 0, 1, 1 };
    int a, b, lst, go;
    vector<int> v;
    int cnt(bool rev = false)
    {
        int ans = 0;
        vector<int> v2 = v;
        if (rev) reverse(v2.begin(), v2.end());
        for (int i = 0; i < 6; i++)
        {
            bool ok = true;
            for (int j = 0; j < v2.size(); j++) if (d[(i + j) % 6] != v2[j])
            {
                ok = false;
                break;
            }
            if (ok) ans++;
        }
        return ans;
    }
}

void Init(int A, int B) 
{
    ::a = A;
    ::b = B;
    lst = -1, go = 0;
    v.clear();
}

int Move(vector<int> y) 
{
    if (a == 2)
    {
        int sum = y[0] + y[1] + (lst != -1);
        if (sum != 2)
        {
            go = 1;
            if (lst != -1) y[lst]++;
            int x = (y[0] == 1 ? 0 : 1);
            if (lst == x) return lst = x, -1;
            return lst = x;
        }
        if (go == 1)
        {
            return lst = (y[0] == 1 ? 0 : 1);
        }
        for (int i = 0; i < y.size(); i++) for (int j = 0; j < y[i]; j++) v.push_back(i);
        int fw = cnt(false), bk = cnt(true);
        if (bk == 0) // ideme sa otocit
        {
            go = 1;
            return -1;
        }
        if (fw == 0) // navzdy budem pokracovat v tomto smere
        {
            go = 1;
            int x = (y[0] == 1 ? 0 : 1);
            return lst = x;
        }
        if (lst == -1) // prvy vrchol
        {
            if (v.back() != 1) reverse(v.begin(), v.end());
            return lst = v[1];
        }
        return lst = (y[0] == 1 ? 0 : 1);
    }
    else
    {
        if (lst != -1) y[lst]++;
        if (!y[0]) return lst = 1;
        if (!y[1]) return lst = 2;
        if (!y[2]) return lst = 0;
    }
}

Compilation message

Catherine.cpp: In function 'int {anonymous}::cnt(bool)':
Catherine.cpp:36:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |             for (int j = 0; j < v2.size(); j++) if (d[(i + j) % 6] != v2[j])
      |                             ~~^~~~~~~~~~~
Catherine.cpp: In function 'int Move(std::vector<int>)':
Catherine.cpp:72:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |         for (int i = 0; i < y.size(); i++) for (int j = 0; j < y[i]; j++) v.push_back(i);
      |                         ~~^~~~~~~~~~
Catherine.cpp:99:1: warning: control reaches end of non-void function [-Wreturn-type]
   99 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 34 ms 15696 KB Output is correct
2 Incorrect 0 ms 796 KB Wrong Answer [5]
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 34 ms 15696 KB Output is correct
2 Incorrect 0 ms 796 KB Wrong Answer [5]
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 26 ms 13292 KB Output is correct
2 Incorrect 1 ms 796 KB Wrong Answer [5]
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 26 ms 13292 KB Output is correct
2 Incorrect 1 ms 796 KB Wrong Answer [5]
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1036 KB Output is correct
2 Correct 0 ms 784 KB Output is correct
3 Correct 0 ms 1044 KB Output is correct
4 Correct 2 ms 1052 KB Output is correct
5 Correct 2 ms 1052 KB Output is correct
6 Correct 2 ms 1048 KB Output is correct
7 Correct 0 ms 1052 KB Output is correct
8 Correct 2 ms 1052 KB Output is correct
9 Correct 2 ms 1048 KB Output is correct
10 Correct 2 ms 1044 KB Output is correct
11 Correct 2 ms 1052 KB Output is correct
12 Correct 1 ms 1044 KB Output is correct
13 Correct 1 ms 1048 KB Output is correct
14 Correct 1 ms 1052 KB Output is correct
15 Correct 1 ms 1048 KB Output is correct
16 Correct 2 ms 1048 KB Output is correct
17 Correct 1 ms 1048 KB Output is correct
18 Correct 1 ms 1048 KB Output is correct
19 Correct 0 ms 1052 KB Output is correct
20 Correct 1 ms 1052 KB Output is correct
21 Correct 1 ms 1048 KB Output is correct
22 Correct 1 ms 1036 KB Output is correct
23 Correct 2 ms 1040 KB Output is correct
24 Correct 2 ms 1048 KB Output is correct
25 Correct 1 ms 1052 KB Output is correct
26 Correct 0 ms 1056 KB Output is correct
27 Correct 2 ms 1052 KB Output is correct
28 Correct 2 ms 1044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 11200 KB Output is correct
2 Correct 24 ms 12520 KB Output is correct
3 Correct 0 ms 780 KB Output is correct
4 Correct 20 ms 11124 KB Output is correct
5 Correct 30 ms 13688 KB Output is correct
6 Correct 27 ms 13632 KB Output is correct
7 Correct 26 ms 12840 KB Output is correct
8 Correct 24 ms 12672 KB Output is correct
9 Correct 37 ms 13648 KB Output is correct
10 Correct 27 ms 13708 KB Output is correct
11 Correct 31 ms 13696 KB Output is correct
12 Correct 27 ms 13700 KB Output is correct
13 Correct 27 ms 13720 KB Output is correct
14 Correct 31 ms 13772 KB Output is correct
15 Correct 36 ms 13676 KB Output is correct
16 Correct 28 ms 13660 KB Output is correct
17 Correct 32 ms 13444 KB Output is correct
18 Correct 26 ms 13440 KB Output is correct
19 Correct 31 ms 13452 KB Output is correct
20 Correct 26 ms 13260 KB Output is correct
21 Correct 27 ms 13464 KB Output is correct
22 Correct 30 ms 13444 KB Output is correct
23 Correct 22 ms 11400 KB Output is correct
24 Correct 27 ms 11388 KB Output is correct
25 Correct 25 ms 11900 KB Output is correct
26 Correct 23 ms 11908 KB Output is correct
27 Correct 27 ms 12412 KB Output is correct
28 Correct 25 ms 12424 KB Output is correct
29 Correct 28 ms 12352 KB Output is correct
30 Correct 31 ms 12416 KB Output is correct
31 Correct 25 ms 11388 KB Output is correct
32 Correct 23 ms 11344 KB Output is correct
33 Correct 24 ms 11652 KB Output is correct
34 Correct 23 ms 11648 KB Output is correct
35 Correct 26 ms 12356 KB Output is correct
36 Correct 24 ms 12400 KB Output is correct
37 Correct 45 ms 12368 KB Output is correct
38 Correct 31 ms 12436 KB Output is correct
39 Correct 36 ms 12488 KB Output is correct
40 Correct 52 ms 12328 KB Output is correct
41 Correct 45 ms 12736 KB Output is correct
42 Correct 52 ms 12844 KB Output is correct
43 Correct 39 ms 12832 KB Output is correct
44 Correct 35 ms 12928 KB Output is correct
45 Correct 32 ms 12924 KB Output is correct
46 Correct 29 ms 13068 KB Output is correct
47 Correct 26 ms 12156 KB Output is correct
48 Correct 36 ms 12236 KB Output is correct
49 Correct 31 ms 12152 KB Output is correct
50 Correct 27 ms 12408 KB Output is correct
51 Correct 28 ms 11596 KB Output is correct
52 Correct 40 ms 11612 KB Output is correct
53 Correct 24 ms 11656 KB Output is correct
54 Correct 24 ms 11572 KB Output is correct
55 Correct 22 ms 11656 KB Output is correct
56 Correct 25 ms 11640 KB Output is correct
57 Correct 23 ms 11616 KB Output is correct
58 Correct 22 ms 11660 KB Output is correct
59 Correct 22 ms 11388 KB Output is correct
60 Correct 26 ms 11596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 11392 KB Output is correct
2 Correct 24 ms 12164 KB Output is correct
3 Correct 0 ms 780 KB Output is correct
4 Correct 19 ms 11100 KB Output is correct
5 Correct 34 ms 13692 KB Output is correct
6 Correct 30 ms 13692 KB Output is correct
7 Correct 27 ms 12688 KB Output is correct
8 Correct 26 ms 12660 KB Output is correct
9 Correct 31 ms 13704 KB Output is correct
10 Correct 34 ms 13696 KB Output is correct
11 Correct 30 ms 13612 KB Output is correct
12 Correct 30 ms 13692 KB Output is correct
13 Correct 27 ms 13696 KB Output is correct
14 Correct 38 ms 13612 KB Output is correct
15 Correct 32 ms 13648 KB Output is correct
16 Correct 30 ms 13696 KB Output is correct
17 Correct 26 ms 13440 KB Output is correct
18 Correct 26 ms 13436 KB Output is correct
19 Correct 30 ms 13440 KB Output is correct
20 Correct 26 ms 13420 KB Output is correct
21 Correct 29 ms 13252 KB Output is correct
22 Correct 32 ms 13444 KB Output is correct
23 Correct 23 ms 11380 KB Output is correct
24 Correct 24 ms 11384 KB Output is correct
25 Correct 24 ms 11900 KB Output is correct
26 Correct 23 ms 11912 KB Output is correct
27 Correct 28 ms 12584 KB Output is correct
28 Correct 33 ms 12424 KB Output is correct
29 Correct 30 ms 12416 KB Output is correct
30 Correct 28 ms 12424 KB Output is correct
31 Correct 24 ms 11392 KB Output is correct
32 Correct 25 ms 11388 KB Output is correct
33 Correct 26 ms 11808 KB Output is correct
34 Correct 26 ms 11856 KB Output is correct
35 Correct 24 ms 12416 KB Output is correct
36 Correct 26 ms 12416 KB Output is correct
37 Correct 27 ms 12440 KB Output is correct
38 Correct 28 ms 12392 KB Output is correct
39 Correct 25 ms 12364 KB Output is correct
40 Correct 26 ms 12432 KB Output is correct
41 Correct 26 ms 12924 KB Output is correct
42 Correct 27 ms 12940 KB Output is correct
43 Correct 26 ms 12928 KB Output is correct
44 Correct 31 ms 12924 KB Output is correct
45 Correct 31 ms 12940 KB Output is correct
46 Correct 30 ms 12928 KB Output is correct
47 Correct 24 ms 12424 KB Output is correct
48 Correct 24 ms 12156 KB Output is correct
49 Correct 26 ms 12160 KB Output is correct
50 Correct 37 ms 12400 KB Output is correct
51 Correct 26 ms 11652 KB Output is correct
52 Correct 22 ms 11732 KB Output is correct
53 Correct 22 ms 11648 KB Output is correct
54 Correct 23 ms 11652 KB Output is correct
55 Correct 27 ms 11656 KB Output is correct
56 Correct 27 ms 11896 KB Output is correct
57 Correct 26 ms 11660 KB Output is correct
58 Correct 26 ms 11652 KB Output is correct
59 Correct 26 ms 11400 KB Output is correct
60 Correct 26 ms 11560 KB Output is correct