답안 #216504

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
216504 2020-03-27T11:56:23 Z dantoh000 길고양이 (JOI20_stray) C++14
15 / 100
69 ms 17436 KB
#include "Anthony.h"
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
namespace {

}  // namespace

std::vector<int> Mark(int N, int M, int A, int B,
                      std::vector<int> U, std::vector<int> V) {
    vector<int> adjlist[N];
    int dist[N];
    int p[N];
    vector<int> ans;
    queue<int> q;
    for (int i = 0; i < M; i++){
        adjlist[U[i]].push_back(V[i]);
        adjlist[V[i]].push_back(U[i]);
    }
    ans.resize(M);
    if (A >= 3){
        memset(dist,-1,sizeof(dist));
        dist[0] = 0;
        p[0] = 0;
        q.push(0);
        while (q.size()){
            int u = q.front(); q.pop();
            for (auto v : adjlist[u]){
                if (dist[v] == -1){
                    //printf("%d -> %d\n",u,v);
                    p[v] = u;
                    dist[v] = dist[u]+1;
                    q.push(v);
                }
            }
        }
        for (int i = 0; i < M; i++){
            if (dist[U[i]] > dist[V[i]]) swap(U[i],V[i]);
            int d = (dist[V[i]]-dist[U[i]]);
            if (p[V[i]] == U[i]) {
                ans[i] = dist[U[i]]%3;
                //printf("edge %d-%d, dist %d,%d: mark %d\n",U[i],V[i],dist[U[i]],dist[V[i]],ans[i]);
            }
            else ans[i] = -1;

        }
        for (int i = 0; i < M; i++){
            if (ans[i] == -1){
                ans[i] = dist[U[i]]%3;
                //printf("useless edge %d-%d dist %d,%d: mark %d\n",U[i],V[i],dist[U[i]],dist[V[i]],ans[i]);
            }
        }
    }
    else{
        memset(dist,-1,sizeof(dist));
        dist[0] = 0;
        p[0] = 0;
        q.push(0);
        while (q.size()){
            int u = q.front(); q.pop();
            int branch = adjlist[u].size() > 2;
            for (auto v : adjlist[u]){
                if (dist[v] == -1){
                    //printf("%d -> %d\n",u,v);
                    p[v] = u;
                    if (branch){
                        dist[v] = 0;
                    }
                    else dist[v] = (dist[u]+1)%8;
                    q.push(v);
                }
            }
        }
        for (int i = 0; i < M; i++){
            if (dist[U[i]] > dist[V[i]]) swap(U[i],V[i]);
            int col;
            if (dist[U[i]] == 0 && dist[V[i]] != 1){
                col = dist[V[i]];
            }
            else col = dist[U[i]];
            if (col == 0 || col == 2 || col == 6 || col == 7) ans[i] = 0;
            else ans[i] = 1;
            //printf("%d %d %d\n",U[i],V[i],ans[i]);
        }
    }
    return ans;
}
#include "Catherine.h"
#include <bits/stdc++.h>
using namespace std;
namespace {

int A, B;
int sure = 0;
vector<int> sofar;
int prv = -2;
}  // namespace

void Init(int A, int B) {
  ::A = A;
  ::B = B;
}

int Move(std::vector<int> y) {
    //printf("new move\n");
    //printf("wasted %d so far, sure ? %d\n",(int)sofar.size(),sure);
    //for (int j = 0; j < A; ++j) printf("%d %d\n",j,y[j]);
    if (A >= 3){
        if (prv == -2){
            if (y[0] == 0) return prv = y[1]?1:2;
            else if (y[1] == 0) return prv = y[2]?2:0;
            else if (y[2] == 0) return prv = y[0]?0:1;
        }
        else{
            return prv = (prv+2)%3;
        }
    }
    else{
        if (!sure){
            if (sofar.empty()){
                if (y[0]+y[1] == 1){
                    sure = true;
                    return y[0]==1?0:1;
                }
            }
            if (y[0]+y[1] > 1){
                if (sofar.empty()){
                    int choose;
                    if (y[0] + y[1] == 2) choose = y[0]?0:1;
                    else{
                        sure = true;
                        choose = y[0] == 1 ? 0 : 1;
                    }
                    sofar.push_back(choose);
                    return choose;
                }
                else{
                    sure = true;
                    if (y[0]==0 || y[1]==0){
                        return -1;
                    }
                    else{
                        return y[0]==1?0:1;
                    }
                }
            }
            else{
                int cur = y[0] == 1 ? 0 : 1;
                if ((int)sofar.size() == 3){
                    sure = true;
                    int CUR = 4*sofar[0] + 2*sofar[1] + sofar[2];
                    int need;
                    if (CUR == 0 || CUR == 2 || CUR == 5 || CUR == 3) need = 1;
                    else need = 0;
                    //printf("so far visited %d %d %d -> %d\n",sofar[0],sofar[1],sofar[2],need);
                    if (cur == need){
                        return -1;
                    }
                    else return cur;
                }
                else{
                    sofar.push_back(cur);
                    return cur;
                }
            }
        }
        else{
            return y[0]==1?0:1;
        }
    }

}

Compilation message

Anthony.cpp: In function 'std::vector<int> Mark(int, int, int, int, std::vector<int>, std::vector<int>)':
Anthony.cpp:39:17: warning: unused variable 'd' [-Wunused-variable]
             int d = (dist[V[i]]-dist[U[i]]);
                 ^

Catherine.cpp: In function 'int Move(std::vector<int>)':
Catherine.cpp:85:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 16132 KB Output is correct
2 Correct 8 ms 776 KB Output is correct
3 Correct 46 ms 15496 KB Output is correct
4 Correct 67 ms 17228 KB Output is correct
5 Correct 66 ms 17436 KB Output is correct
6 Correct 53 ms 15808 KB Output is correct
7 Correct 53 ms 15872 KB Output is correct
8 Correct 60 ms 16644 KB Output is correct
9 Correct 62 ms 16672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 16132 KB Output is correct
2 Correct 8 ms 776 KB Output is correct
3 Correct 46 ms 15496 KB Output is correct
4 Correct 67 ms 17228 KB Output is correct
5 Correct 66 ms 17436 KB Output is correct
6 Correct 53 ms 15808 KB Output is correct
7 Correct 53 ms 15872 KB Output is correct
8 Correct 60 ms 16644 KB Output is correct
9 Correct 62 ms 16672 KB Output is correct
10 Correct 50 ms 13996 KB Output is correct
11 Correct 50 ms 14000 KB Output is correct
12 Correct 49 ms 13892 KB Output is correct
13 Correct 50 ms 14012 KB Output is correct
14 Correct 51 ms 14028 KB Output is correct
15 Correct 56 ms 14636 KB Output is correct
16 Correct 69 ms 16936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 52 ms 13712 KB Output is correct
2 Correct 9 ms 780 KB Output is correct
3 Correct 45 ms 13356 KB Output is correct
4 Correct 67 ms 15052 KB Output is correct
5 Correct 63 ms 15148 KB Output is correct
6 Correct 51 ms 13668 KB Output is correct
7 Correct 55 ms 13820 KB Output is correct
8 Correct 57 ms 14488 KB Output is correct
9 Correct 57 ms 14488 KB Output is correct
10 Correct 55 ms 14096 KB Output is correct
11 Correct 59 ms 14236 KB Output is correct
12 Correct 59 ms 14152 KB Output is correct
13 Correct 56 ms 14220 KB Output is correct
14 Correct 60 ms 14500 KB Output is correct
15 Correct 60 ms 14496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 52 ms 13712 KB Output is correct
2 Correct 9 ms 780 KB Output is correct
3 Correct 45 ms 13356 KB Output is correct
4 Correct 67 ms 15052 KB Output is correct
5 Correct 63 ms 15148 KB Output is correct
6 Correct 51 ms 13668 KB Output is correct
7 Correct 55 ms 13820 KB Output is correct
8 Correct 57 ms 14488 KB Output is correct
9 Correct 57 ms 14488 KB Output is correct
10 Correct 55 ms 14096 KB Output is correct
11 Correct 59 ms 14236 KB Output is correct
12 Correct 59 ms 14152 KB Output is correct
13 Correct 56 ms 14220 KB Output is correct
14 Correct 60 ms 14500 KB Output is correct
15 Correct 60 ms 14496 KB Output is correct
16 Correct 47 ms 12024 KB Output is correct
17 Correct 47 ms 12116 KB Output is correct
18 Correct 48 ms 12096 KB Output is correct
19 Correct 49 ms 12088 KB Output is correct
20 Correct 54 ms 12500 KB Output is correct
21 Correct 51 ms 12236 KB Output is correct
22 Correct 56 ms 14772 KB Output is correct
23 Correct 49 ms 12224 KB Output is correct
24 Correct 49 ms 12096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 912 KB Wrong Answer [5]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 46 ms 11504 KB Wrong Answer [5]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 45 ms 11464 KB Wrong Answer [5]
2 Halted 0 ms 0 KB -