답안 #804607

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
804607 2023-08-03T10:16:18 Z I_Love_EliskaM_ Roller Coaster Railroad (IOI16_railroad) C++14
34 / 100
55 ms 10960 KB
#include "railroad.h"
#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for(int i=0;i<n;++i)
#define pb push_back
#define all(x) x.begin(), x.end()
using ll = long long;
#define pi pair<int,int>
#define f first
#define s second

struct DSU {
    vector<int> p,sz;
    DSU(int n) {
        forn(i,n) p.pb(i), sz.pb(1);
    }
    int get(int u) {
        return p[u]==u?u:get(p[u]);
    }
    void uni(int u, int v) {
        u=get(u),v=get(v);
        if (u==v) return;
        if (sz[u]<sz[v]) swap(u,v);
        sz[u]+=sz[v];
        p[v]=u;
    }
};

ll dp[1<<16][20];
bool foo(int a, int b) {
    return __builtin_popcount(a) < __builtin_popcount(b);
}
ll scuza(vector<int> s, vector<int> t) {

    int n=s.size();
    s.pb(-1); t.pb(0);
    vector<int> b;
    forn(i,1<<n) b.pb(i);
    sort(all(b),foo);
    forn(i,n+1) forn(j,1<<n) dp[j][i]=1e18;
    dp[0][n]=0;
    for(auto&m:b) {
        forn(i,n+1) {
            if (m) if (!(m&(1<<i))) continue;
            forn(j,n) {
                if (m&(1<<j)) continue;
                dp[m|(1<<j)][j]=min(dp[m|(1<<j)][j],dp[m][i] + max(t[i]-s[j],0));
            }
        }
    }
    ll ans=1e18;
    forn(i,n) ans=min(ans,dp[(1<<n)-1][i]);
    return ans;
 
}

ll plan_roller_coaster(vector<int> s, vector<int> t) {
    int n=s.size();

    if (n<=16) return scuza(s,t);
    return 0;

    s.pb(1e9+7);
    t.pb(-1);
    ++n;

    int m=0;
    set<int> st; forn(i,n) st.insert(s[i]), st.insert(t[i]);
    map<int,int> c;
    for(auto&x:st) c[x]=m++;

    vector<int> pr(m);
    forn(i,n) s[i]=c[s[i]], t[i]=c[t[i]];

    DSU dsu(m);
    forn(i,n) {
        pr[t[i]]++;
        pr[s[i]]--;
        dsu.uni(s[i],t[i]);
    }
    for(int i=1; i<m; ++i) pr[i]+=pr[i-1];

    forn(i,m) {
        if (pr[i]<0) return 1;
        if (pr[i]>0) dsu.uni(i,i+1);
    }
    int ans=1;
    forn(i,n) ans&=dsu.get(i)==dsu.get(0);
    return !ans;

}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 304 KB n = 2
2 Correct 0 ms 212 KB n = 2
3 Correct 1 ms 212 KB n = 2
4 Correct 1 ms 308 KB n = 2
5 Correct 1 ms 212 KB n = 2
6 Correct 0 ms 212 KB n = 2
7 Correct 0 ms 212 KB n = 3
8 Correct 0 ms 304 KB n = 3
9 Correct 1 ms 212 KB n = 3
10 Correct 1 ms 340 KB n = 8
11 Correct 1 ms 340 KB n = 8
12 Correct 1 ms 304 KB n = 8
13 Correct 1 ms 340 KB n = 8
14 Correct 1 ms 312 KB n = 8
15 Correct 1 ms 340 KB n = 8
16 Correct 1 ms 340 KB n = 8
17 Correct 1 ms 308 KB n = 8
18 Correct 1 ms 340 KB n = 8
19 Correct 1 ms 212 KB n = 3
20 Correct 1 ms 212 KB n = 7
21 Correct 1 ms 340 KB n = 8
22 Correct 1 ms 308 KB n = 8
23 Correct 1 ms 340 KB n = 8
24 Correct 1 ms 340 KB n = 8
25 Correct 1 ms 340 KB n = 8
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 304 KB n = 2
2 Correct 0 ms 212 KB n = 2
3 Correct 1 ms 212 KB n = 2
4 Correct 1 ms 308 KB n = 2
5 Correct 1 ms 212 KB n = 2
6 Correct 0 ms 212 KB n = 2
7 Correct 0 ms 212 KB n = 3
8 Correct 0 ms 304 KB n = 3
9 Correct 1 ms 212 KB n = 3
10 Correct 1 ms 340 KB n = 8
11 Correct 1 ms 340 KB n = 8
12 Correct 1 ms 304 KB n = 8
13 Correct 1 ms 340 KB n = 8
14 Correct 1 ms 312 KB n = 8
15 Correct 1 ms 340 KB n = 8
16 Correct 1 ms 340 KB n = 8
17 Correct 1 ms 308 KB n = 8
18 Correct 1 ms 340 KB n = 8
19 Correct 1 ms 212 KB n = 3
20 Correct 1 ms 212 KB n = 7
21 Correct 1 ms 340 KB n = 8
22 Correct 1 ms 308 KB n = 8
23 Correct 1 ms 340 KB n = 8
24 Correct 1 ms 340 KB n = 8
25 Correct 1 ms 340 KB n = 8
26 Correct 1 ms 340 KB n = 8
27 Correct 1 ms 340 KB n = 8
28 Correct 1 ms 340 KB n = 8
29 Correct 50 ms 10832 KB n = 16
30 Correct 50 ms 10832 KB n = 16
31 Correct 55 ms 10932 KB n = 16
32 Correct 47 ms 10832 KB n = 16
33 Correct 53 ms 10960 KB n = 16
34 Correct 45 ms 10924 KB n = 16
35 Correct 45 ms 10960 KB n = 16
36 Correct 22 ms 5704 KB n = 15
37 Correct 1 ms 340 KB n = 8
38 Correct 51 ms 10960 KB n = 16
39 Correct 44 ms 10920 KB n = 16
40 Correct 1 ms 340 KB n = 9
41 Correct 44 ms 10960 KB n = 16
42 Correct 44 ms 10832 KB n = 16
43 Correct 47 ms 10832 KB n = 16
44 Correct 1 ms 340 KB n = 9
45 Correct 21 ms 5588 KB n = 15
46 Correct 45 ms 10832 KB n = 16
47 Correct 45 ms 10952 KB n = 16
48 Correct 45 ms 10948 KB n = 16
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 7236 KB n = 199999
2 Incorrect 37 ms 7368 KB answer is not correct: 0 instead of 1
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 304 KB n = 2
2 Correct 0 ms 212 KB n = 2
3 Correct 1 ms 212 KB n = 2
4 Correct 1 ms 308 KB n = 2
5 Correct 1 ms 212 KB n = 2
6 Correct 0 ms 212 KB n = 2
7 Correct 0 ms 212 KB n = 3
8 Correct 0 ms 304 KB n = 3
9 Correct 1 ms 212 KB n = 3
10 Correct 1 ms 340 KB n = 8
11 Correct 1 ms 340 KB n = 8
12 Correct 1 ms 304 KB n = 8
13 Correct 1 ms 340 KB n = 8
14 Correct 1 ms 312 KB n = 8
15 Correct 1 ms 340 KB n = 8
16 Correct 1 ms 340 KB n = 8
17 Correct 1 ms 308 KB n = 8
18 Correct 1 ms 340 KB n = 8
19 Correct 1 ms 212 KB n = 3
20 Correct 1 ms 212 KB n = 7
21 Correct 1 ms 340 KB n = 8
22 Correct 1 ms 308 KB n = 8
23 Correct 1 ms 340 KB n = 8
24 Correct 1 ms 340 KB n = 8
25 Correct 1 ms 340 KB n = 8
26 Correct 1 ms 340 KB n = 8
27 Correct 1 ms 340 KB n = 8
28 Correct 1 ms 340 KB n = 8
29 Correct 50 ms 10832 KB n = 16
30 Correct 50 ms 10832 KB n = 16
31 Correct 55 ms 10932 KB n = 16
32 Correct 47 ms 10832 KB n = 16
33 Correct 53 ms 10960 KB n = 16
34 Correct 45 ms 10924 KB n = 16
35 Correct 45 ms 10960 KB n = 16
36 Correct 22 ms 5704 KB n = 15
37 Correct 1 ms 340 KB n = 8
38 Correct 51 ms 10960 KB n = 16
39 Correct 44 ms 10920 KB n = 16
40 Correct 1 ms 340 KB n = 9
41 Correct 44 ms 10960 KB n = 16
42 Correct 44 ms 10832 KB n = 16
43 Correct 47 ms 10832 KB n = 16
44 Correct 1 ms 340 KB n = 9
45 Correct 21 ms 5588 KB n = 15
46 Correct 45 ms 10832 KB n = 16
47 Correct 45 ms 10952 KB n = 16
48 Correct 45 ms 10948 KB n = 16
49 Correct 33 ms 7236 KB n = 199999
50 Incorrect 37 ms 7368 KB answer is not correct: 0 instead of 1
51 Halted 0 ms 0 KB -