답안 #210673

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
210673 2020-03-18T01:40:18 Z thebes Restore Array (RMI19_restore) C++14
20 / 100
543 ms 1192 KB
#include <bits/stdc++.h>
#define DEBUG 1
using namespace std;

namespace output{
    void __(short x){cout<<x;}
    void __(unsigned x){cout<<x;}
    void __(int x){cout<<x;}
    void __(long long x){cout<<x;}
    void __(unsigned long long x){cout<<x;}
    void __(double x){cout<<x;}
    void __(long double x){cout<<x;}
    void __(char x){cout<<x;}
    void __(const char*x){cout<<x;}
    void __(const string&x){cout<<x;}
    void __(bool x){cout<<(x?"true":"false");}
    template<class S,class T>
    void __(const pair<S,T>&x){__(DEBUG?"(":""),__(x.first),__(DEBUG?", ":" "),__(x.second),__(DEBUG?")":"");}
    template<class T>
    void __(const vector<T>&x){__(DEBUG?"{":"");bool _=0;for(const auto&v:x)__(_?DEBUG?", ":" ":""),__(v),_=1;__(DEBUG?"}":"");}
    template<class T>
    void __(const set<T>&x){__(DEBUG?"{":"");bool _=0;for(const auto&v:x)__(_?DEBUG?", ":" ":""),__(v),_=1;__(DEBUG?"}":"");}
    template<class T>
    void __(const multiset<T>&x){__(DEBUG?"{":"");bool _=0;for(const auto&v:x)__(_?DEBUG?", ":" ":""),__(v),_=1;__(DEBUG?"}":"");}
    template<class S,class T>
    void __(const map<S,T>&x){__(DEBUG?"{":"");bool _=0;for(const auto&v:x)__(_?DEBUG?", ":" ":""),__(v),_=1;__(DEBUG?"}":"");}
    void pr(){cout<<"\n";}
    template<class S,class... T>
    void pr(const S&a,const T&...b){__(a);if(sizeof...(b))__(' ');pr(b...);}
}

using namespace output;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<int,char> pic;
typedef pair<double,double> pdd;
typedef pair<ld,ld> pld;
typedef vector<int> vi;
typedef vector<ll> vl;

#define pb push_back
#define fox(i,x,y) for(int i=(x);i<=(y);i++)
#define foxr(i,x,y) for(int i=(y);i>=(x);i--)

const int MN = 5005;
int N, M, i, x, y, k, t, arr[MN], vs[MN], st[MN], f;
struct con{int x, mn, mx;};
vector<con> adj[MN];
queue<int> go;

int main(){
    for(scanf("%d%d",&N,&M),i=1;i<=M;i++){
        scanf("%d%d%d%d",&x,&y,&k,&t); y++;
        if(t) adj[x].pb({y,y-x-k+1,y-x}), adj[y].pb({x,x-y,x-y+k-1});
        else adj[x].pb({y,0,y-x-k}), adj[y].pb({x,x-y+k,0});
    }
    for(i=1;i<=N;i++){
        adj[i-1].pb({i,0,1});
        adj[i].pb({i-1,-1,0});
        st[i] = 1;
        go.push(i);
    }
    st[0] = 1;
    go.push(0);
    while(go.size()){
        x=go.front(); go.pop();
        st[x]=0;
        for(auto v : adj[x]){
            f = 0;
            if(arr[v.x]-arr[x]<v.mn){
                arr[v.x]=v.mn+arr[x];
                f = 1;
            }
            if(arr[v.x]-arr[x]>v.mx){
                arr[v.x]=v.mx+arr[x];
                f = 1;
            }
            if(f){
                vs[v.x]++;
                if(vs[v.x]>9000){
                    printf("-1\n");
                    return 0;
                }
                if(!st[v.x]){
                    go.push(v.x);
                    st[v.x]=1;
                }
            }
        }
    }
    for(i=1;i<=N;i++)
        printf("%d ",arr[i]-arr[i-1]);
    printf("\n");
    return 0;
}

Compilation message

restore.cpp: In function 'int main()':
restore.cpp:55:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(scanf("%d%d",&N,&M),i=1;i<=M;i++){
         ~~~~~~~~~~~~~~~~~~~^~~~
restore.cpp:56:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d%d",&x,&y,&k,&t); y++;
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 504 KB Output is correct
4 Correct 5 ms 504 KB Output is correct
5 Correct 6 ms 504 KB Output is correct
6 Correct 6 ms 504 KB Output is correct
7 Correct 5 ms 504 KB Output is correct
8 Correct 5 ms 504 KB Output is correct
9 Correct 5 ms 504 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 1016 KB Output is correct
2 Correct 12 ms 1144 KB Output is correct
3 Correct 10 ms 1020 KB Output is correct
4 Correct 48 ms 1144 KB Output is correct
5 Correct 543 ms 1144 KB Output is correct
6 Correct 535 ms 1016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 1016 KB Output is correct
2 Correct 12 ms 1144 KB Output is correct
3 Correct 10 ms 1020 KB Output is correct
4 Correct 48 ms 1144 KB Output is correct
5 Correct 543 ms 1144 KB Output is correct
6 Correct 535 ms 1016 KB Output is correct
7 Correct 11 ms 1144 KB Output is correct
8 Correct 11 ms 1144 KB Output is correct
9 Correct 11 ms 1144 KB Output is correct
10 Correct 43 ms 1144 KB Output is correct
11 Correct 512 ms 1192 KB Output is correct
12 Correct 473 ms 1144 KB Output is correct
13 Correct 11 ms 1144 KB Output is correct
14 Incorrect 518 ms 1144 KB Output isn't correct
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 504 KB Output is correct
4 Correct 5 ms 504 KB Output is correct
5 Correct 6 ms 504 KB Output is correct
6 Correct 6 ms 504 KB Output is correct
7 Correct 5 ms 504 KB Output is correct
8 Correct 5 ms 504 KB Output is correct
9 Correct 5 ms 504 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 10 ms 1016 KB Output is correct
12 Correct 12 ms 1144 KB Output is correct
13 Correct 10 ms 1020 KB Output is correct
14 Correct 48 ms 1144 KB Output is correct
15 Correct 543 ms 1144 KB Output is correct
16 Correct 535 ms 1016 KB Output is correct
17 Correct 11 ms 1144 KB Output is correct
18 Correct 11 ms 1144 KB Output is correct
19 Correct 11 ms 1144 KB Output is correct
20 Correct 43 ms 1144 KB Output is correct
21 Correct 512 ms 1192 KB Output is correct
22 Correct 473 ms 1144 KB Output is correct
23 Correct 11 ms 1144 KB Output is correct
24 Incorrect 518 ms 1144 KB Output isn't correct
25 Halted 0 ms 0 KB -