Submission #1074020

# Submission time Handle Problem Language Result Execution time Memory
1074020 2024-08-25T06:33:13 Z 8e7 Tricolor Lights (JOI24_tricolor) C++17
0 / 100
71 ms 18972 KB
#include "Anna.h"
#include <bits/stdc++.h>
using namespace std;
namespace{
#ifdef zisk
void debug(){cout << endl;}
template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);}
template<class T> void pary(T l, T r) {
	while (l != r) cout << *l << " ", l++;
	cout << endl;
}
#else
#define debug(...) 0
#define pary(...) 0
#endif
#define ll long long
#define maxn 200005
#define pii pair<int, int>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);


ll po(ll a, ll n) {
    ll ret = 1;
    while (n) {
        if (n & 1) ret = ret * a;
        n >>= 1;
        a = a * a;
    }
    return ret;
}
vector<int> adj[200000];
vector<int> build_path() {
    int n = 10;
    auto good = [&] (ll x) {
        for (int i = 0;i < n;i++) {
            if (x % 3 == 0) return true;
            x /= 3;
        }
        return false;
    };
    ll m = po(3, n);
    for (int i = 0;i < m;i++) {
        for (int j = 0;j < 3;j++) {
            int to = (i * 3 + j) % m;
            if (!good(i) && j != 0) continue;
            if (i == 0 && j == 0) continue;
            adj[i].push_back(to); 
        }
    } 
    vector<int> path, stk;
    int cur = 0;
    stk.push_back(cur);
    while (stk.size()) {
        cur = stk.back();
        int tmp = cur;
        while (adj[cur].size()) {
            int v = adj[cur].back();
            adj[cur].pop_back();
            cur = v;
            stk.push_back(v);
            break;
        }        
        if (tmp != cur) continue;
        path.push_back(cur);
        stk.pop_back();
    }
    reverse(path.begin(), path.end());
    return path;
}

int to_int(char c) {
    if (c == 'R') return 0;
    else if (c == 'G') return 1;
    else return 2;
}

char to_char(int i) {
    const string S = "RGB";
    return S[i];
}

int add_diff(int prv, int res) {
    if ((prv+1)%3 != res) return (prv+1)%3;
    else return (prv+2)%3;
}
void add_bit(std::vector<int> &ret, std::vector<int> &v, int bit) {
    //add semantic bit, could be 0/1/2, which takes up v[ind] and v[ind+1]
    int ind = ret.size();
    if (ind >= v.size()) return;
    if (ind + 1 >= v.size()) {
        ret.push_back(add_diff(ret.back(), v[ind]));
        return;
    }
    int done = 0;
    for (int i = 1;i < 3;i++) {
        for (int j = 1;j < 3;j++) {
            int vi = (v[ind] + i) % 3, vj = (v[ind+1] + j) % 3;
            if ((vj - vi + 3) % 3 == bit) {
                ret.push_back(vi);
                ret.push_back(vj);
                done = 1;
                break;
            }
        }
        if (done) break;
    } 
    ind = ret.size();
    if (ind >= v.size()) return;
    ret.push_back(add_diff(ret.back(), v[ind]));
}
}

pair<string, int> anna(int N, string S) {
    vector<int> v(N, 0), ret;
    for (int i = 0;i < N;i++) v[i] = to_int(S[i]);
    ret.push_back((v[0] + 1) %3);
    vector<int> nodes = build_path(); 
    for (int i = 0;i < 10;i++) add_bit(ret, v, 0);
    for (int i = 1;i < nodes.size();i++) {
        if (ret.size() >= N) break;
        add_bit(ret, v, nodes[i] % 3);
    } 
    while (ret.size() >= N) ret.pop_back(); 
    pary(nodes.begin(), nodes.begin() + 20);
    
    int L = min(N, 34);
    string T;
    for (int i = 0;i < N;i++) T.push_back(to_char(ret[i]));
    return make_pair(T, L);
}
#include "Bruno.h"
#include <bits/stdc++.h>
using namespace std;
namespace{
#ifdef zisk
void debug(){cout << endl;}
template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);}
template<class T> void pary(T l, T r) {
	while (l != r) cout << *l << " ", l++;
	cout << endl;
}
#else
#define debug(...) 0
#define pary(...) 0
#endif
#define ll long long
#define maxn 500005
#define pii pair<int, int>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
int N, L;
ll po(ll a, ll n) {
    ll ret = 1;
    while (n) {
        if (n & 1) ret = ret * a;
        n >>= 1;
        a = a * a;
    }
    return ret;
}
vector<int> adj[200000];
vector<int> build_path() {
    int n = 10;
    auto good = [&] (ll x) {
        for (int i = 0;i < n;i++) {
            if (x % 3 == 0) return true;
            x /= 3;
        }
        return false;
    };
    ll m = po(3, n);
    for (int i = 0;i < m;i++) {
        for (int j = 0;j < 3;j++) {
            int to = (i * 3 + j) % m;
            if (!good(i) && j != 0) continue;
            if (i == 0 && j == 0) continue;
            adj[i].push_back(to); 
        }
    } 
    vector<int> path, stk;
    int cur = 0;
    stk.push_back(cur);
    while (stk.size()) {
        cur = stk.back();
        int tmp = cur;
        while (adj[cur].size()) {
            int v = adj[cur].back();
            adj[cur].pop_back();
            cur = v;
            stk.push_back(v);
            break;
        }        
        if (tmp != cur) continue;
        path.push_back(cur);
        stk.pop_back();
    }
    reverse(path.begin(), path.end());
    return path;
}
vector<int> path;
int edge_ind[maxn];
}

void init(int N, int l) {
    ::N = N;
    ::L = l;
    debug("L", l);
    path = build_path();
    for (int i = 1;i < path.size();i++) {
        int val = path[i-1] * 3 + path[i] % 3; 
        edge_ind[val] = i;
    }
}

int bruno(string s) {
    if (N == L) return 1;
    vector<int> v[3];
    bool has_zero[3] = {0, 0, 0};
    for (int i = 1;i < L;i++) {
        v[i%3].push_back((s[i] - s[i-1] + 3) % 3);
        if (s[i] == s[i-1]) has_zero[i%3] = 1;
    }
    int col = 0;
    for (int i = 0;i < 3;i++) {
        if (has_zero[i] && !has_zero[(i+1)%3]) col = i;
    } 
    int num = 0;
    for (int i:v[col]) num = num * 3 + i; 
    int pos = -1 + 3 * edge_ind[num]; 
    pos += 1 - col;
    if (col == 0) pos -= 3;
    debug(num, edge_ind[num], col, pos);
    //debug(num, col);
    
    debug("Answer", pos);
    return pos;
}

Compilation message

Anna.cpp: In function 'void {anonymous}::add_bit(std::vector<int>&, std::vector<int>&, int)':
Anna.cpp:91:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   91 |     if (ind >= v.size()) return;
      |         ~~~~^~~~~~~~~~~
Anna.cpp:92:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   92 |     if (ind + 1 >= v.size()) {
      |         ~~~~~~~~^~~~~~~~~~~
Anna.cpp:110:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  110 |     if (ind >= v.size()) return;
      |         ~~~~^~~~~~~~~~~
Anna.cpp: In function 'std::pair<std::__cxx11::basic_string<char>, int> anna(int, std::string)':
Anna.cpp:121:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  121 |     for (int i = 1;i < nodes.size();i++) {
      |                    ~~^~~~~~~~~~~~~~
Anna.cpp:122:24: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  122 |         if (ret.size() >= N) break;
      |             ~~~~~~~~~~~^~~~
Anna.cpp:125:23: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  125 |     while (ret.size() >= N) ret.pop_back();
      |            ~~~~~~~~~~~^~~~
Anna.cpp:14:19: warning: statement has no effect [-Wunused-value]
   14 | #define pary(...) 0
      |                   ^
Anna.cpp:126:5: note: in expansion of macro 'pary'
  126 |     pary(nodes.begin(), nodes.begin() + 20);
      |     ^~~~

Bruno.cpp: In function 'void init(int, int)':
Bruno.cpp:13:20: warning: statement has no effect [-Wunused-value]
   13 | #define debug(...) 0
      |                    ^
Bruno.cpp:78:5: note: in expansion of macro 'debug'
   78 |     debug("L", l);
      |     ^~~~~
Bruno.cpp:80:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |     for (int i = 1;i < path.size();i++) {
      |                    ~~^~~~~~~~~~~~~
Bruno.cpp: In function 'int bruno(std::string)':
Bruno.cpp:13:20: warning: statement has no effect [-Wunused-value]
   13 | #define debug(...) 0
      |                    ^
Bruno.cpp:103:5: note: in expansion of macro 'debug'
  103 |     debug(num, edge_ind[num], col, pos);
      |     ^~~~~
Bruno.cpp:13:20: warning: statement has no effect [-Wunused-value]
   13 | #define debug(...) 0
      |                    ^
Bruno.cpp:106:5: note: in expansion of macro 'debug'
  106 |     debug("Answer", pos);
      |     ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 56 ms 18844 KB Output is correct
2 Correct 69 ms 18952 KB Output is correct
3 Correct 49 ms 18940 KB Output is correct
4 Correct 57 ms 18928 KB Output is correct
5 Correct 53 ms 18964 KB Output is correct
6 Incorrect 61 ms 18848 KB Wrong Answer [5]
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 56 ms 18844 KB Output is correct
2 Correct 69 ms 18952 KB Output is correct
3 Correct 49 ms 18940 KB Output is correct
4 Correct 57 ms 18928 KB Output is correct
5 Correct 53 ms 18964 KB Output is correct
6 Incorrect 61 ms 18848 KB Wrong Answer [5]
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 56 ms 18844 KB Output is correct
2 Correct 69 ms 18952 KB Output is correct
3 Correct 49 ms 18940 KB Output is correct
4 Correct 57 ms 18928 KB Output is correct
5 Correct 53 ms 18964 KB Output is correct
6 Incorrect 61 ms 18848 KB Wrong Answer [5]
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 56 ms 18844 KB Output is correct
2 Correct 69 ms 18952 KB Output is correct
3 Correct 49 ms 18940 KB Output is correct
4 Correct 57 ms 18928 KB Output is correct
5 Correct 53 ms 18964 KB Output is correct
6 Incorrect 61 ms 18848 KB Wrong Answer [5]
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 46 ms 18972 KB Output is correct
2 Correct 51 ms 18764 KB Output is correct
3 Correct 48 ms 18876 KB Output is correct
4 Correct 71 ms 18872 KB Output is correct
5 Partially correct 53 ms 18796 KB Partially correct
6 Incorrect 55 ms 18952 KB Wrong Answer [5]
7 Halted 0 ms 0 KB -