답안 #958694

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
958694 2024-04-06T11:25:30 Z hariaakas646 Uzastopni (COCI15_uzastopni) C++14
64 / 160
308 ms 65536 KB
#include <bits/stdc++.h>

using namespace std;

#define scd(t) scanf("%d", &t)
#define sclld(t) scanf("%lld", &t)
#define forr(i, j, k) for (int i = j; i < k; i++)
#define frange(i, j) forr(i, 0, j)
#define all(cont) cont.begin(), cont.end()
#define mp make_pair
#define pb push_back
#define f first
#define s second
typedef long long int lli;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<lli> vll;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef map<int, int> mpii;
typedef set<int> seti;
typedef multiset<int> mseti;
typedef long double ld;

void usaco()
{
    freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
//    freopen("problem.out", "w", stdout);
}

vi val;
vvi graph;

vector<vector<bitset<101>>> dp;

bool verify(bitset<101> bt, int v1) {
    bool valid = true;
    int v = 1;
    forr(i, v1+1, 101) {
        if(bt[i] == 0) v = 0;
        if(bt[i] != v) {
            valid = false;
        }
    }
    v = 1;
    for(int i=v1-1; i>=1; i--) {
        if(bt[i] == 0) v = 0;
        if(bt[i] != v) {
            valid = false;
        }
    }
    return valid;      
}

void dfs(int x) {
    bitset<101> tmp;
    tmp[val[x]] = 1;
    dp[x].pb(tmp);
    vector<bitset<101>> glob;
    glob.pb(tmp);
    for(auto e : graph[x]) {
        dfs(e);
        vector<bitset<101>> curr;
        for(auto bt : dp[e]) {
            
            for(auto bt2 : glob) {
                if((bt & bt2).count()) continue;
                auto bt3 = (bt | bt2);
                curr.pb(bt3);
            }
        }
        for(auto bt : curr) {
            glob.pb(bt);
            if(verify(bt, val[x])) dp[x].pb(bt);
        }
    }
    // sort(all(dp[x]));
    // dp[x].erase(unique(all(dp[x])))
}

int main() {
    // usaco();
    int n;
    scd(n);

    graph = vvi(n+1);
    val = vi(n+1);

    forr(i, 1, n+1) scd(val[i]);

    frange(i, n-1) {
        int a, b;
        scd(a);
        scd(b);
        graph[a].pb(b);
    }
    dp = vector<vector<bitset<101>>>(n+1);
    dfs(1);
    // vector<bitset<101>> up, down;
    // vector<bitset<101>> out;
    
    // for(auto e : graph[1]) {
    //     vector<bitset<101>> upt, downt;
    //     for(auto bt : dp[e]) {
    //         bool u = false;
    //         bool d = false;
    //         bool valid = true;
    //         int v = 1;
    //         forr(i, val[1]+1, 101) {
    //             if(bt[i] == 0) v = 0;
    //             if(v) u = true;
    //             if(bt[i] != v) {
    //                 valid = false;
    //             }
    //         }
    //         v = 1;
    //         for(int i=val[1]-1; i>=1; i--) {
    //             if(bt[i] == 0) v = 0;
    //             if(v) d = true;
    //             if(bt[i] != v) {
    //                 valid = false;
    //             }
    //         }
    //         if(valid) {
    //             out.pb(bt);
    //             if(u && !d) {
    //                 for(auto bt1 : down) {
    //                     out.pb(bt | bt1);
    //                 }
    //                 upt.pb(bt);
    //             }
    //             if(d && !u) {
    //                 for(auto bt1 : up) {
    //                     out.pb(bt | bt1);
    //                 }
    //                 downt.pb(bt);
    //             }
    //         }
    //     }
    //     for(auto e : downt) down.pb(e);
    //     for(auto e : upt) up.pb(e);
    // }
    printf("%d", (int)dp[1].size());
}

Compilation message

uzastopni.cpp: In function 'void usaco()':
uzastopni.cpp:29:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |     freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
uzastopni.cpp: In function 'int main()':
uzastopni.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
uzastopni.cpp:86:5: note: in expansion of macro 'scd'
   86 |     scd(n);
      |     ^~~
uzastopni.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
uzastopni.cpp:91:21: note: in expansion of macro 'scd'
   91 |     forr(i, 1, n+1) scd(val[i]);
      |                     ^~~
uzastopni.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
uzastopni.cpp:95:9: note: in expansion of macro 'scd'
   95 |         scd(a);
      |         ^~~
uzastopni.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
uzastopni.cpp:96:9: note: in expansion of macro 'scd'
   96 |         scd(b);
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Incorrect 1 ms 348 KB Output isn't correct
5 Incorrect 0 ms 364 KB Output isn't correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Incorrect 13 ms 1556 KB Output isn't correct
12 Incorrect 12 ms 1628 KB Output isn't correct
13 Incorrect 9 ms 1784 KB Output isn't correct
14 Incorrect 75 ms 14776 KB Output isn't correct
15 Correct 79 ms 14928 KB Output is correct
16 Incorrect 75 ms 14908 KB Output isn't correct
17 Incorrect 9 ms 1624 KB Output isn't correct
18 Incorrect 10 ms 1628 KB Output isn't correct
19 Runtime error 290 ms 65536 KB Execution killed with signal 9
20 Runtime error 308 ms 65536 KB Execution killed with signal 9