Submission #962738

# Submission time Handle Problem Language Result Execution time Memory
962738 2024-04-14T07:43:42 Z GrindMachine Stray Cat (JOI20_stray) C++17
5 / 100
42 ms 19748 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define setbits(x) __builtin_popcountll(x)
#define ff first
#define ss second
#define conts continue
#define ceil2(x,y) ((x+y-1)/(y))
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define yes cout << "Yes" << endl
#define no cout << "No" << endl

#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define rev(i,s,e) for(int i = s; i >= e; --i)
#define trav(i,a) for(auto &i : a)

template<typename T>
void amin(T &a, T b) {
    a = min(a,b);
}

template<typename T>
void amax(T &a, T b) {
    a = max(a,b);
}

#ifdef LOCAL
#include "debug.h"
#else
#define debug(x) 42
#endif

/*

refs:
edi
https://codeforces.com/blog/entry/74871?#comment-591498

*/

const int MOD = 1e9 + 7;
const int N = 1e5 + 5;
const int inf1 = int(1e9) + 5;
const ll inf2 = ll(1e18) + 5;

#include "Anthony.h"

namespace anthony {
    set<string> st1,st2;
    string chain = "";

    void precalc(){
        int n = 6;
        rep(mask,1<<n){
            string s(2*n,'?');
            rep(i,n){
                ll b = 0;
                if(mask&(1<<i)){
                    b = 1;
                }
                s[i] = s[i+n] = char('0'+b);
            }

            st1.clear(), st2.clear();
            rep(i,n){
                string t = string(s.begin()+i,s.begin()+i+5);
                st1.insert(t);
                reverse(all(t));
                st2.insert(t);
            }

            bool ok = true;
            trav(t,st1){
                if(st2.count(t)){
                    ok = false;
                }
            }

            if(ok){
                chain = string(s.begin(),s.begin()+n);
                return;
            }
        }
    }

    vector<pii> adj[N];
    vector<int> val;

    void dfs1(int u, int p, int prev_typ, int ptr){
        for(auto [v,id] : adj[u]){
            if(v == p) conts;
            if(sz(adj[v]) == 2){
                int nxt_ptr = 0;
                if(ptr != -1){
                    nxt_ptr = (ptr+1)%6;
                }
                else{
                    if(prev_typ == 0){
                        nxt_ptr = 0;
                    }
                    else{
                        nxt_ptr = 2;
                    }
                }

                val[id] = chain[nxt_ptr]-'0';
                dfs1(v,u,-1,nxt_ptr);
            }
            else{
                int nxt_typ = 0;
                if(prev_typ != -1){
                    nxt_typ = prev_typ^1;
                }
                else{
                    nxt_typ = (chain[ptr]-'0')^1;
                }

                val[id] = nxt_typ;
                dfs1(v,u,nxt_typ,-1);
            }
        }
    }

}  // namespace

using namespace anthony;

std::vector<int> Mark(int n, int m, int A, int B,
                      std::vector<int> U, std::vector<int> V) {
    // std::vector<int> X(M);
    // for (int i = 0; i < M; ++i) {
    //     X[i] = FunctionExample(i, A);
    // }
    // return X;

    precalc();
    rep(i,m){
        int u = U[i], v = V[i];
        adj[u].pb({v,i}), adj[v].pb({u,i});
    }

    val = vector<int>(m,-1);
    dfs1(0,-1,1,-1);

    debug(val);
    return val;
}
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define setbits(x) __builtin_popcountll(x)
#define ff first
#define ss second
#define conts continue
#define ceil2(x,y) ((x+y-1)/(y))
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define yes cout << "Yes" << endl
#define no cout << "No" << endl

#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define rev(i,s,e) for(int i = s; i >= e; --i)
#define trav(i,a) for(auto &i : a)

template<typename T>
void amin(T &a, T b) {
    a = min(a,b);
}

template<typename T>
void amax(T &a, T b) {
    a = max(a,b);
}

// #ifdef LOCAL
// #include "debug.h"
// #else
// #define debug(x) 42
// #endif

/*

refs:
edi
https://codeforces.com/blog/entry/74871?#comment-591498

*/

const int MOD = 1e9 + 7;
const int N = 1e5 + 5;
const int inf1 = int(1e9) + 5;
const ll inf2 = ll(1e18) + 5;

#include "Catherine.h"

namespace catherine {
    int A,B;
    set<string> st1,st2;
    string chain = "";

    void precalc(){
        int n = 6;
        rep(mask,1<<n){
            string s(2*n,'?');
            rep(i,n){
                ll b = 0;
                if(mask&(1<<i)){
                    b = 1;
                }
                s[i] = s[i+n] = char('0'+b);
            }

            st1.clear(), st2.clear();
            rep(i,n){
                string t = string(s.begin()+i,s.begin()+i+5);
                st1.insert(t);
                reverse(all(t));
                st2.insert(t);
            }

            bool ok = true;
            trav(t,st1){
                if(st2.count(t)){
                    ok = false;
                }
            }

            if(ok){
                chain = string(s.begin(),s.begin()+n);
                return;
            }
        }
    }

    int move_num = 0;
    bool decided = false;
    int prev_edge = 0;
    string curr_chain = "";

}  // namespace

using namespace catherine;

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

int Move(std::vector<int> y) {
    // ++variable_example;
    // for (int j = 0; j < A; ++j) {
    //     if (y[j] != 0) {
    //       return j;
    //     }
    // }
    // return -1;

    int sum = y[0]+y[1];
    if(!sum){
        decided = true;
        return -1;
    }

    if(decided){
        if(sum == 1){
            if(y[0]) prev_edge = 0;
            else prev_edge = 1;
        }
        else{
            prev_edge ^= 1;
        }

        return prev_edge;
    }

    move_num++;
    if(move_num == 1){
        if(sum == 1){
            if(y[0]) prev_edge = 0;
            else prev_edge = 1;
            decided = true;
            return prev_edge;
        }
        else if(sum >= 3){
            if(y[0] == 1) prev_edge = 0;
            else prev_edge = 1;
            decided = true;
            return prev_edge;
        }
        else{
            if(y[0]) prev_edge = 0;
            else prev_edge = 1;
            curr_chain.pb(char('0'+prev_edge));
            return prev_edge;
        }
    }

    if(sum >= 2){
        decided = true;
        y[prev_edge]++;
        int nxt_edge = 0;
        if(y[0] == 1) nxt_edge = 0;
        else nxt_edge = 1;

        if(nxt_edge == prev_edge) return -1;
        else return prev_edge = nxt_edge;
    }

    if(y[0]) prev_edge = 0;
    else prev_edge = 1;

    if(move_num == 7){
        decided = true;
        if(st1.count(curr_chain)){
            // wrong direction
            prev_edge = curr_chain.back()-'0';
            return -1;
        }
        else{
            return prev_edge;
        }
    }

    curr_chain.pb(char('0'+prev_edge));
    return prev_edge;
}

Compilation message

Anthony.cpp: In function 'std::vector<int> Mark(int, int, int, int, std::vector<int>, std::vector<int>)':
Anthony.cpp:46:18: warning: statement has no effect [-Wunused-value]
   46 | #define debug(x) 42
      |                  ^~
Anthony.cpp:161:5: note: in expansion of macro 'debug'
  161 |     debug(val);
      |     ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 40 ms 18028 KB Output is correct
2 Correct 1 ms 3096 KB Output is correct
3 Correct 23 ms 16768 KB Output is correct
4 Correct 35 ms 19748 KB Output is correct
5 Incorrect 40 ms 19528 KB Wrong Answer [6]
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 40 ms 18028 KB Output is correct
2 Correct 1 ms 3096 KB Output is correct
3 Correct 23 ms 16768 KB Output is correct
4 Correct 35 ms 19748 KB Output is correct
5 Incorrect 40 ms 19528 KB Wrong Answer [6]
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 27 ms 15712 KB Output is correct
2 Correct 1 ms 3096 KB Output is correct
3 Correct 23 ms 14444 KB Output is correct
4 Correct 37 ms 17536 KB Output is correct
5 Incorrect 30 ms 17536 KB Wrong Answer [6]
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 27 ms 15712 KB Output is correct
2 Correct 1 ms 3096 KB Output is correct
3 Correct 23 ms 14444 KB Output is correct
4 Correct 37 ms 17536 KB Output is correct
5 Incorrect 30 ms 17536 KB Wrong Answer [6]
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3352 KB Output is correct
2 Correct 1 ms 3096 KB Output is correct
3 Correct 1 ms 3612 KB Output is correct
4 Correct 2 ms 3356 KB Output is correct
5 Correct 2 ms 3360 KB Output is correct
6 Correct 3 ms 3356 KB Output is correct
7 Correct 2 ms 3352 KB Output is correct
8 Correct 3 ms 3352 KB Output is correct
9 Correct 2 ms 3360 KB Output is correct
10 Correct 2 ms 3352 KB Output is correct
11 Correct 2 ms 3360 KB Output is correct
12 Correct 2 ms 3344 KB Output is correct
13 Correct 3 ms 3344 KB Output is correct
14 Correct 2 ms 3352 KB Output is correct
15 Correct 2 ms 3360 KB Output is correct
16 Correct 2 ms 3356 KB Output is correct
17 Correct 2 ms 3352 KB Output is correct
18 Correct 2 ms 3340 KB Output is correct
19 Correct 2 ms 3360 KB Output is correct
20 Correct 2 ms 3344 KB Output is correct
21 Correct 2 ms 3360 KB Output is correct
22 Correct 2 ms 3352 KB Output is correct
23 Correct 2 ms 3360 KB Output is correct
24 Correct 2 ms 3360 KB Output is correct
25 Correct 2 ms 3352 KB Output is correct
26 Correct 2 ms 3368 KB Output is correct
27 Correct 3 ms 3352 KB Output is correct
28 Correct 2 ms 3352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 13172 KB Output is correct
2 Correct 30 ms 14372 KB Output is correct
3 Correct 1 ms 3492 KB Output is correct
4 Correct 23 ms 12852 KB Output is correct
5 Correct 31 ms 15996 KB Output is correct
6 Correct 34 ms 15836 KB Output is correct
7 Incorrect 25 ms 14972 KB Wrong Answer [6]
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 25 ms 13168 KB Output is correct
2 Correct 30 ms 14316 KB Output is correct
3 Correct 2 ms 3092 KB Output is correct
4 Correct 27 ms 13036 KB Output is correct
5 Correct 42 ms 15924 KB Output is correct
6 Correct 30 ms 15992 KB Output is correct
7 Correct 26 ms 14972 KB Output is correct
8 Incorrect 26 ms 14876 KB Wrong Answer [6]
9 Halted 0 ms 0 KB -