Submission #525359

# Submission time Handle Problem Language Result Execution time Memory
525359 2022-02-11T13:11:58 Z idas Stations (IOI20_stations) C++17
0 / 100
887 ms 696 KB
#include <bits/stdc++.h>
#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr)
#define FOR(i, begin, end) for(int i = (begin); i < (end); i++)
#define TSTS int ttt; cin >> ttt; while(ttt--) solve()
#define all(x) (x).begin(), (x).end()
#define le(vec) vec[vec.size()-1]
#define sz(x) ((int)((x).size()))
#define pb push_back
#define s second
#define f first

using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long double, long double> pdd;

const int INF=1e9, MOD=1e9+7, mod=998244353;
const ll LINF=1e18;

void setIO()
{
    FAST_IO;
}

void setIO(string s)
{
    FAST_IO;
    freopen((s+".in").c_str(), "r", stdin);
    freopen((s+".out").c_str(), "w", stdout);
}

const int N=1e3+10;
int dp[N], lb[N], lst;
bool v[N];
vi ad[N];

void build(int u, int pst)
{
    for(auto x : ad[u]){
        if(x==pst) continue;
        build(x, u);
        dp[u]+=dp[x];
    }
    dp[u]++;
}

void dfs(int u, int pst, bool mx)
{
    if(mx){
        while(v[lst]) lst--;
        lb[u]=lst;
        v[lst]=true;
    }
    for(auto x : ad[u]){
        if(x==pst) continue;
        if(mx){
            int now=lb[u];
            while(v[now]) now--;
            lb[x]=now-dp[x]+1;
            assert(!v[lb[x]]);
            v[lb[x]]=true;
        }
        dfs(x, u, !mx);
    }
}

vi label(int n, int k, vi uu, vi vv)
{
    FOR(i, 0, n+1) ad[i].clear(), v[i]=false, dp[i]=0, lb[i]=0;
    FOR(i, 0, n-1)
    {
        ad[uu[i]].pb(vv[i]);
        ad[vv[i]].pb(uu[i]);
    }
    lst=n;
    build(0, -1);
    dfs(0, -1, true);
    vi ans;
    FOR(i, 0, n) ans.pb(lb[i]);
    return ans;
}

int find_next_station(int s, int t, vi c)
{
    if(s<c[0]){
        FOR(i, 0, sz(c))
        {
            if(c[i]>t){
                return c[i];
            }
        }
        return le(c);
    }
    else{
        for(int i=sz(c)-1; i>=0; i--){
            if(c[i]<t){
                return c[i];
            }
        }
        return c[0];
    }
}

Compilation message

stations.cpp: In function 'void setIO(std::string)':
stations.cpp:32:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |     freopen((s+".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
stations.cpp:33:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |     freopen((s+".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 562 ms 532 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 463 ms 520 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 515 ms 696 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 887 ms 400 KB Output is correct
2 Incorrect 616 ms 500 KB Wrong query response.
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 569 ms 656 KB Wrong query response.
2 Halted 0 ms 0 KB -