Submission #951369

# Submission time Handle Problem Language Result Execution time Memory
951369 2024-03-21T17:42:07 Z sofiefu The Xana coup (BOI21_xanadu) C++14
0 / 100
1000 ms 524288 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define vo vector
#define pb push_back
#define se second
#define fi first
#define all(v) v.begin(), v.end()
typedef vector<int> vi;
typedef pair<int, int> pii;
#define umap unordered_map
#define uset unordered_set

#define rep(i, a, b) for(int i=(a); i<b; i++)
#define pr1(x) cerr << #x << '=' << x << ' ';
//for google contests
#define repd(i, a, b) for(int i=(b-1); i >= a; i--)
void _pr(signed x) {cerr << x;}
void _pr(long long x) {cerr << x;}
void _pr(unsigned long long x) {cerr << x;}
void _pr(double x) {cerr << x;}
void _pr(char x) {cerr << '\'' << x << '\'';}
void _pr(const char* x) {cerr << x;}
void _pr(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V> void _pr(const pair<T, V> &x);
template<typename T, typename V> void _pr(const pair<T, V> &x) {cerr << "\e[95m" << "[ "; _pr(x.first); cerr << ", "; _pr(x.second); cerr << "\e[95m" << ']';}
template<typename T> void _pr(const T &x) {int F=0; cerr << '{'; for(auto &i: x) cerr << (F++ ? ", " : ""), _pr(i); cerr << "\e[91m" << '}';}
template <typename T, typename... V> void _pr(T t, V... v) {_pr(t); if(sizeof...(v)) cerr << ", "; _pr(v...);}
#define pr(x...) cerr << "\e[91m" << __func__ << ':' << __LINE__ << " [" << #x << "] = ["; _pr(x); cerr << "\e[91m" << ']' << "\033[0m"  << endl;

//go for outline with ;, then details
int const inf = LLONG_MAX, mxn = 1e5+4;
int n, ans=inf;
vo<vi> adj(mxn);

signed main(){
    cin.tie(0)->sync_with_stdio(0);
    cin>>n;
    rep(i, 0, n-1){
        int a, b; cin>>a>>b; a--, --b;
        adj[a].pb(b), adj[b].pb(a);
    }

    string s, goal;
    rep(i, 0, n) {char c; cin>>c; s.pb(c); goal.pb('0');}
    

    umap<string, int> dist;
    queue<string> qu; qu.push(goal);
    while(qu.size()){
        string v = qu.front(); qu.pop();

        if(v==s) {ans = dist[v]; break;}
        rep(u, 0, n){
            string tmp = v;
            //turn on u
            tmp[u]^=1; 
            for(auto x: adj[u]){
                tmp[x]^=1;
            }

            if(!dist.count(tmp)){
                dist[tmp] = dist[v]+1;
                qu.push(tmp);
            }
        }
    }

    if(ans==inf) cout << "impossible";
    else cout << ans;

    //checka om svaret alltid är mindre än N


}
# Verdict Execution time Memory Grader output
1 Correct 60 ms 8500 KB Output is correct
2 Correct 18 ms 3928 KB Output is correct
3 Correct 105 ms 16068 KB Output is correct
4 Execution timed out 1022 ms 58028 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 60 ms 8500 KB Output is correct
2 Correct 18 ms 3928 KB Output is correct
3 Correct 105 ms 16068 KB Output is correct
4 Execution timed out 1022 ms 58028 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 395 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 339 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 60 ms 8500 KB Output is correct
2 Correct 18 ms 3928 KB Output is correct
3 Correct 105 ms 16068 KB Output is correct
4 Execution timed out 1022 ms 58028 KB Time limit exceeded
5 Halted 0 ms 0 KB -