답안 #531657

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
531657 2022-03-01T08:15:46 Z i_am_noob Restore Array (RMI19_restore) C++17
20 / 100
600 ms 892 KB
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast,unroll-loops")

#define ll long long
//#define int ll
#define ull unsigned ll
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define chkmin(a,b) (a=min(a,b))
#define chkmax(a,b) (a=max(a,b))
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define inf 1010000000
//#define inf 4000000000000000000
#define eps 1e-9
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define print0(a) cout << (a) << ' '
#define ykh mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#ifdef i_am_noob
#define bug(...) cerr << "#" << __LINE__ << ' ' << #__VA_ARGS__ << "- ", _do(__VA_ARGS__)
template<typename T> void _do(T && x) {cerr << x << endl;}
template<typename T, typename ...S> void _do(T && x, S&&...y) {cerr << x << ", "; _do(y...);}
#else
#define bug(...) 777771449
#endif

const int mod=1000000007;
const int maxn=5005,maxm=5,maxk=7777714;

//i_am_noob
int n,m,dis[maxn],par[maxn];
vector<vector<pii>> adj(maxn);
deque<int> dq;
bool vis[maxn],vis2[maxn];

bool check(){
    memset(vis2,0,sizeof vis2);
    rep(n+2) if(!vis2[i]){
        int u=i;
        vis2[u]=1;
        bool flag=0;
        rep1(_,n+2){
            u=par[u];
            if(u==-1){
                flag=1;
                break;
            }
            vis2[u]=1;
        }
        if(!flag) return false;
    }
    return true;
}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void orzck(){
    cin >> n >> m;
    rep(n) adj[i].pb({i+1,1}),adj[i+1].pb({i,0});
    rep(n+1) adj[n+1].pb({i,0});
    rep(n+2) dis[i]=inf;
    rep(m){
        int l,r,k,x;
        cin >> l >> r >> k >> x;
        if(x==0){
            adj[l].pb({r+1,r+1-l-k});
            bug(l,r+1,r+1-l-k);
        }
        else{
            adj[r+1].pb({l,-(r-l+2-k)});
            bug(r+1,l,-(r-l+2-k));
        }
    }
    dq.pb(n+1);
    dis[n+1]=0;
    vis[n+1]=1;
    rep(n+2) par[i]=-1;
    int de=0;
    while(!dq.empty()){
        int u=dq.front();
        dq.pop_front();
        vis[u]=0;
        bool flag=0;
        bug(u);
        for(auto [v,w]: adj[u]){
            if(dis[u]+w<dis[v]){
                dis[v]=dis[u]+w;
                par[v]=u;
                de++;
                if(de==n+2){
                    de=0;
                    flag=1;
                    if(!check()){
                        cout << "-1\n";
                        return;
                    }
                }
                if(vis[v]) continue;
                dq.pb(v);
                vis[v]=1;
            }
        }
        if(flag) shuffle(all(dq),rng);
    }
    if(!check()){
        cout << "-1\n";
        return;
    }
    rep(n) cout << dis[i+1]-dis[i] << ' ';
    cout << "\n";
}

signed main(){
    ios_base::sync_with_stdio(0),cin.tie(0);
    orzck();
    return 0;
}

Compilation message

restore.cpp: In function 'void orzck()':
restore.cpp:31:18: warning: statement has no effect [-Wunused-value]
   31 | #define bug(...) 777771449
      |                  ^~~~~~~~~
restore.cpp:74:13: note: in expansion of macro 'bug'
   74 |             bug(l,r+1,r+1-l-k);
      |             ^~~
restore.cpp:31:18: warning: statement has no effect [-Wunused-value]
   31 | #define bug(...) 777771449
      |                  ^~~~~~~~~
restore.cpp:78:13: note: in expansion of macro 'bug'
   78 |             bug(r+1,l,-(r-l+2-k));
      |             ^~~
restore.cpp:31:18: warning: statement has no effect [-Wunused-value]
   31 | #define bug(...) 777771449
      |                  ^~~~~~~~~
restore.cpp:91:9: note: in expansion of macro 'bug'
   91 |         bug(u);
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 844 KB Output is correct
2 Correct 5 ms 844 KB Output is correct
3 Correct 4 ms 844 KB Output is correct
4 Correct 24 ms 872 KB Output is correct
5 Correct 4 ms 844 KB Output is correct
6 Correct 6 ms 844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 844 KB Output is correct
2 Correct 5 ms 844 KB Output is correct
3 Correct 4 ms 844 KB Output is correct
4 Correct 24 ms 872 KB Output is correct
5 Correct 4 ms 844 KB Output is correct
6 Correct 6 ms 844 KB Output is correct
7 Correct 20 ms 844 KB Output is correct
8 Correct 19 ms 844 KB Output is correct
9 Correct 18 ms 892 KB Output is correct
10 Correct 70 ms 892 KB Output is correct
11 Correct 6 ms 844 KB Output is correct
12 Correct 5 ms 844 KB Output is correct
13 Correct 21 ms 892 KB Output is correct
14 Correct 167 ms 876 KB Output is correct
15 Execution timed out 875 ms 880 KB Time limit exceeded
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 4 ms 844 KB Output is correct
12 Correct 5 ms 844 KB Output is correct
13 Correct 4 ms 844 KB Output is correct
14 Correct 24 ms 872 KB Output is correct
15 Correct 4 ms 844 KB Output is correct
16 Correct 6 ms 844 KB Output is correct
17 Correct 20 ms 844 KB Output is correct
18 Correct 19 ms 844 KB Output is correct
19 Correct 18 ms 892 KB Output is correct
20 Correct 70 ms 892 KB Output is correct
21 Correct 6 ms 844 KB Output is correct
22 Correct 5 ms 844 KB Output is correct
23 Correct 21 ms 892 KB Output is correct
24 Correct 167 ms 876 KB Output is correct
25 Execution timed out 875 ms 880 KB Time limit exceeded
26 Halted 0 ms 0 KB -