답안 #973269

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
973269 2024-05-01T17:04:08 Z steveonalex 경찰관과 강도 (BOI14_coprobber) C++17
30 / 100
120 ms 2896 KB
#include <bits/stdc++.h>
#include "coprobber.h"

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define MASK(i) (1LL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
#define ALL(v) (v).begin(), (v).end()

ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}

ll LASTBIT(ll mask){return (mask) & (-mask);}
int pop_cnt(ll mask){return __builtin_popcountll(mask);}
int ctz(ll mask){return __builtin_ctzll(mask);}
int logOf(ll mask){return __lg(mask);}

// mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
mt19937_64 rng(1);
ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);}

template <class T1, class T2>
    bool maximize(T1 &a, T2 b){
        if (a < b) {a = b; return true;}
        return false;
    }

template <class T1, class T2>
    bool minimize(T1 &a, T2 b){
        if (a > b) {a = b; return true;}
        return false;
    }

template <class T>
    void printArr(T& container, string separator = " ", string finish = "\n"){
        for(auto item: container) cout << item << separator;
        cout << finish;
    }


template <class T>
    void remove_dup(vector<T> &a){
        sort(ALL(a));
        a.resize(unique(ALL(a)) - a.begin());
    }

const int N = 500;
const int INF = 1e9 + 69;

int graph[N][N];
bitset<N> edging[N];
int cop;

int current_subtask;

int n;


namespace Sub1{
    int nextMove(int R){
        vector<int> S; S.push_back(cop);
        for(int i = 0; i<n; ++i) if (edging[cop][i]) S.push_back(i);

        pair<int, int> best = {INF, INF};
        for(int i: S){
            int cur = graph[i][R];
            minimize(best, make_pair(cur, i));
        }
        cop = best.second;

        return best.second;

    }
}

namespace Sub2{
    int r, c;
    void init(){
        for(int i = 1; i<n; ++i) if (edging[i].count() == 2){
            c = i + 1, r = n / c; break;
        }
    }

    int nextMove(int R){
        pair<int, int> u = make_pair(cop / c, cop % c);
        pair<int, int> v = make_pair(R / c, R % c);

        if (abs(u.first - v.first) == 1 && abs(u.second - v.second) == 1){
            return cop;
        }
        else if (abs(u.second - v.second) < abs(u.first - v.first)){
            u.first += (v.first - u.first) / abs(u.first - v.first);
            cop = u.first * c + u.second;
            return cop;
        }
        else{
            u.second += (v.second - u.second) / abs(u.second - v.second);
            cop = u.first * c + u.second;
            return cop;
        }
    }
}

int start(int _n, bool A[N][N]){
    n = _n;

    for(int i = 0; i<n; ++i) for(int j= 0; j<n; ++j) edging[i][j] = A[i][j];

    int cnt = 0;
    for(int i = 0; i<n; ++i) cnt += edging[i].count();

    if (cnt == (n-1) * 2) current_subtask = 1;
    else{
        current_subtask = 2;
        Sub2::init();
    }

    for(int i = 0; i<n; ++i) for(int j = 0; j<n; ++j) {
        if (A[i][j]) graph[i][j] = 1;
        else graph[i][j] = INF;
        if (i == j) graph[i][j] = 0;
    }

    for(int k = 0; k<n; ++k) for(int i= 0; i<n; ++i) for(int j = 0; j<n; ++j) 
        minimize(graph[i][j], graph[i][k] + graph[k][j]);

    cop = 0;
    return 0;
    // if (biggest_cycle <= 4) return 0;
    // return -1;
}


int nextMove(int R){
    if (current_subtask == 1) return Sub1::nextMove(R);
    else return Sub2::nextMove(R);
}


// int main(void){
//     ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

//     int n, m; cin >> n >> m;


//     // int n; cin >> n;
//     bool a[N][N];
//     memset(a, 0, sizeof a);

//     for(int i = 0; i<m; ++i){
//         int u, v; cin >> u >> v;
//         a[u][v] = a[v][u] = 1;
//     }

//     int cop = start(n, a);
//     cout << "? " << cop << endl;

//     int crim; cin >> crim;
//     while(cop != crim){
//         cop = nextMove(crim);
//         if (cop == crim) break;
//         cout << "? " << cop << endl;
//         cin >> crim;
//     }

//     cout << "Crim caught!!!!" << endl;

//     return 0;
// }
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2392 KB Output is correct
3 Correct 0 ms 2392 KB Output is correct
4 Correct 112 ms 2896 KB Output is correct
5 Correct 18 ms 2776 KB Output is correct
6 Correct 111 ms 2720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 114 ms 2712 KB Output is correct
4 Correct 110 ms 2712 KB Output is correct
5 Correct 100 ms 2880 KB Output is correct
6 Correct 120 ms 2888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2392 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Incorrect 1 ms 2392 KB Cop cannot catch the robber, but start() did not return -1
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2392 KB Output is correct
3 Correct 0 ms 2392 KB Output is correct
4 Correct 112 ms 2896 KB Output is correct
5 Correct 18 ms 2776 KB Output is correct
6 Correct 111 ms 2720 KB Output is correct
7 Correct 0 ms 2392 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 114 ms 2712 KB Output is correct
10 Correct 110 ms 2712 KB Output is correct
11 Correct 100 ms 2880 KB Output is correct
12 Correct 120 ms 2888 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 0 ms 2392 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 1 ms 2392 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
19 Incorrect 1 ms 2392 KB Cop cannot catch the robber, but start() did not return -1
20 Halted 0 ms 0 KB -