답안 #637495

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
637495 2022-09-02T09:24:58 Z fatemetmhr Cats or Dogs (JOI18_catdog) C++17
38 / 100
3000 ms 15168 KB
//  ~Be name khoda~  //
 
#include "catdog.h"
#include<bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
#define pb       push_back
#define mp       make_pair
#define all(x)   x.begin(), x.end()
#define fi       first
#define se       second
 
const int maxn  =  1e6   + 10;
const int maxn5 =  5e5   + 10;
const int maxnt =  1.2e6 + 10;
const int maxn3 =  1e3   + 10;
const int mod   =  1e9   +  7;
const ll  inf   =  1e18;
 
int n, catt[maxn5], dogg[maxn5], a[maxn5];
int st[maxn5], ans = 0;
vector <int> adj[maxn5];
 
void initialize(int N, std::vector<int> A, std::vector<int> B) {
    n = N;
    for(int i = 0; i < n - 1; i++){
        A[i]--; B[i]--;
        adj[A[i]].pb(B[i]);
        adj[B[i]].pb(A[i]);
    }
    return;
}
 
void dfs(int v, int par){
    int cat = 0, dog = 0;
    for(auto u : adj[v]) if(u != par){
        dfs(u, v);
        if(st[u] == 1)
            dog++;
        if(st[u] == 2)
            cat++;
    }
    if(a[v] == 1){
        ans += cat;
        st[v] = 1;
    }
    if(a[v] == 2){
        ans += dog;
        st[v] = 2;
    }
    if(a[v] == 0){
        if(cat < dog){
            st[v] = 1;
            ans += cat;
        }
        if(cat > dog){
            st[v] = 2;
            ans += dog;
        }
        if(cat == dog){
            st[v] = 0;
            ans += cat;
        }

    }
    //cout << v << ' ' << par << ' ' << cat << ' ' << dog << ' ' << a[v] << ' ' << st[v] << ' ' << ans << endl;
    return;
}
 
int output(){
    ans = 0;
    dfs(0, -1);
    return ans;
}
 
int cat(int v) {
    v--;
    a[v] = 1;
    return output();
}
 
int dog(int v) {
    v--;
    a[v] = 2;
    return output();
}
 
int neighbor(int v) {
    v--;
    a[v] = 0;
    return output();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 11988 KB Output is correct
2 Correct 7 ms 11960 KB Output is correct
3 Correct 8 ms 12032 KB Output is correct
4 Correct 7 ms 12000 KB Output is correct
5 Correct 7 ms 12044 KB Output is correct
6 Correct 7 ms 11988 KB Output is correct
7 Correct 7 ms 12060 KB Output is correct
8 Correct 7 ms 11988 KB Output is correct
9 Correct 6 ms 11988 KB Output is correct
10 Correct 7 ms 12060 KB Output is correct
11 Correct 6 ms 12012 KB Output is correct
12 Correct 6 ms 11988 KB Output is correct
13 Correct 6 ms 12060 KB Output is correct
14 Correct 7 ms 12024 KB Output is correct
15 Correct 6 ms 11988 KB Output is correct
16 Correct 8 ms 12040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 11988 KB Output is correct
2 Correct 7 ms 11960 KB Output is correct
3 Correct 8 ms 12032 KB Output is correct
4 Correct 7 ms 12000 KB Output is correct
5 Correct 7 ms 12044 KB Output is correct
6 Correct 7 ms 11988 KB Output is correct
7 Correct 7 ms 12060 KB Output is correct
8 Correct 7 ms 11988 KB Output is correct
9 Correct 6 ms 11988 KB Output is correct
10 Correct 7 ms 12060 KB Output is correct
11 Correct 6 ms 12012 KB Output is correct
12 Correct 6 ms 11988 KB Output is correct
13 Correct 6 ms 12060 KB Output is correct
14 Correct 7 ms 12024 KB Output is correct
15 Correct 6 ms 11988 KB Output is correct
16 Correct 8 ms 12040 KB Output is correct
17 Correct 16 ms 12100 KB Output is correct
18 Correct 15 ms 12112 KB Output is correct
19 Correct 11 ms 12100 KB Output is correct
20 Correct 6 ms 11988 KB Output is correct
21 Correct 11 ms 12080 KB Output is correct
22 Correct 10 ms 11988 KB Output is correct
23 Correct 18 ms 12104 KB Output is correct
24 Correct 15 ms 11988 KB Output is correct
25 Correct 10 ms 12080 KB Output is correct
26 Correct 7 ms 12020 KB Output is correct
27 Correct 7 ms 11988 KB Output is correct
28 Correct 8 ms 12116 KB Output is correct
29 Correct 18 ms 12164 KB Output is correct
30 Correct 7 ms 11988 KB Output is correct
31 Correct 7 ms 11988 KB Output is correct
32 Correct 8 ms 12012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 11988 KB Output is correct
2 Correct 7 ms 11960 KB Output is correct
3 Correct 8 ms 12032 KB Output is correct
4 Correct 7 ms 12000 KB Output is correct
5 Correct 7 ms 12044 KB Output is correct
6 Correct 7 ms 11988 KB Output is correct
7 Correct 7 ms 12060 KB Output is correct
8 Correct 7 ms 11988 KB Output is correct
9 Correct 6 ms 11988 KB Output is correct
10 Correct 7 ms 12060 KB Output is correct
11 Correct 6 ms 12012 KB Output is correct
12 Correct 6 ms 11988 KB Output is correct
13 Correct 6 ms 12060 KB Output is correct
14 Correct 7 ms 12024 KB Output is correct
15 Correct 6 ms 11988 KB Output is correct
16 Correct 8 ms 12040 KB Output is correct
17 Correct 16 ms 12100 KB Output is correct
18 Correct 15 ms 12112 KB Output is correct
19 Correct 11 ms 12100 KB Output is correct
20 Correct 6 ms 11988 KB Output is correct
21 Correct 11 ms 12080 KB Output is correct
22 Correct 10 ms 11988 KB Output is correct
23 Correct 18 ms 12104 KB Output is correct
24 Correct 15 ms 11988 KB Output is correct
25 Correct 10 ms 12080 KB Output is correct
26 Correct 7 ms 12020 KB Output is correct
27 Correct 7 ms 11988 KB Output is correct
28 Correct 8 ms 12116 KB Output is correct
29 Correct 18 ms 12164 KB Output is correct
30 Correct 7 ms 11988 KB Output is correct
31 Correct 7 ms 11988 KB Output is correct
32 Correct 8 ms 12012 KB Output is correct
33 Execution timed out 3067 ms 15168 KB Time limit exceeded
34 Halted 0 ms 0 KB -