답안 #480926

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
480926 2021-10-18T19:53:06 Z DJeniUp Toll (BOI17_toll) C++17
56 / 100
3000 ms 11132 KB
#pragma GCC Optimize("O3")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pairll;
typedef pair<ll,pairll>pairlll;
typedef pair<pairll,pairll>pairllll;
typedef long double ld;
typedef pair<ll,string>pairls;

#define INF 1000000000000007
#define MOD 1000000007
#define pb push_back
#define fr first
#define sc second
#define endl '\n'

ll k,n,m,o,res[10007],t[50007][7];

vector<pairll>v[50007];

struct D{
    ll l,r,q;
}d[10007];

bool mcp(D d1, D d2){
    if(d1.l/k==d2.l/k)return d1.r>d2.r;
    return d1.l<d2.l;
}

int main() {
    

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //cin>>k>>n>>m>>o;
    scanf("%lld %lld %lld %lld", &k, &n, &m, &o);
    for(int i=1;i<=m;i++){
        ll l,r,c;
        //cin>>l>>r>>c;
        scanf("%lld %lld %lld", &l, &r, &c);
        v[r].pb({l,c});
    }
    for(int i=1;i<=o;i++){
        //cin>>d[i].l>>d[i].r;
        scanf("%lld %lld", &d[i].l, &d[i].r);
        d[i].q=i;
    }
    sort(d+1,d+1+o,mcp);
    ll x=0;
    for(int i=1;i<=o;i++){
        if(d[i].l/k!=d[i-1].l/k || i==1){
            x=d[i].l-d[i].l%k;
            for(int j=0;j<k;j++){
                t[x][j]=t[x+1][j]=t[x+2][j]=t[x+3][j]=t[x+4][j]=INF;
            }
            t[x][0]=t[x+1][1]=t[x+2][2]=t[x+3][3]=t[x+4][4]=0;
            for(int j=x+k;j<=d[i].r;j++){
                for(int y=0;y<k;y++){
                    t[j][y]=INF;
                    for(auto it: v[j]){
                        t[j][y]=min(t[j][y],t[it.fr][y]+it.sc);
                    }
                }
            }
        }
        if(d[i].l>d[i].r || t[d[i].r][d[i].l%k]==INF)res[d[i].q]=-1;
        else res[d[i].q]=t[d[i].r][d[i].l%k];
    }
    for(int i=1;i<=o;i++){
        //cout<<res[i]<<endl;
        printf("%lld\n", res[i]);
    }

}

Compilation message

toll.cpp:1: warning: ignoring '#pragma GCC Optimize' [-Wunknown-pragmas]
    1 | #pragma GCC Optimize("O3")
      | 
toll.cpp: In function 'int main()':
toll.cpp:41:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |     scanf("%lld %lld %lld %lld", &k, &n, &m, &o);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
toll.cpp:45:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |         scanf("%lld %lld %lld", &l, &r, &c);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
toll.cpp:50:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |         scanf("%lld %lld", &d[i].l, &d[i].r);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1203 ms 6084 KB Output is correct
2 Correct 1 ms 1484 KB Output is correct
3 Correct 1 ms 1484 KB Output is correct
4 Correct 1 ms 1484 KB Output is correct
5 Correct 4 ms 1612 KB Output is correct
6 Correct 3 ms 1612 KB Output is correct
7 Correct 3 ms 1612 KB Output is correct
8 Correct 1032 ms 6080 KB Output is correct
9 Correct 952 ms 6008 KB Output is correct
10 Correct 321 ms 4532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 7064 KB Output is correct
2 Correct 1 ms 1484 KB Output is correct
3 Correct 1 ms 1484 KB Output is correct
4 Correct 1 ms 1484 KB Output is correct
5 Correct 1 ms 1484 KB Output is correct
6 Correct 1 ms 1484 KB Output is correct
7 Correct 6 ms 1888 KB Output is correct
8 Correct 6 ms 1868 KB Output is correct
9 Correct 26 ms 6084 KB Output is correct
10 Correct 65 ms 8444 KB Output is correct
11 Correct 49 ms 7108 KB Output is correct
12 Correct 36 ms 6580 KB Output is correct
13 Correct 63 ms 7896 KB Output is correct
14 Correct 39 ms 5828 KB Output is correct
15 Correct 32 ms 5196 KB Output is correct
16 Correct 32 ms 5152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1484 KB Output is correct
2 Correct 1 ms 1484 KB Output is correct
3 Correct 1 ms 1484 KB Output is correct
4 Correct 1 ms 1484 KB Output is correct
5 Correct 1 ms 1484 KB Output is correct
6 Correct 2 ms 1484 KB Output is correct
7 Correct 2 ms 1612 KB Output is correct
8 Correct 4 ms 1612 KB Output is correct
9 Correct 3 ms 1612 KB Output is correct
10 Correct 38 ms 5736 KB Output is correct
11 Correct 68 ms 6752 KB Output is correct
12 Correct 111 ms 8092 KB Output is correct
13 Correct 125 ms 8516 KB Output is correct
14 Correct 98 ms 7332 KB Output is correct
15 Correct 67 ms 5220 KB Output is correct
16 Correct 62 ms 5068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1484 KB Output is correct
2 Correct 1 ms 1484 KB Output is correct
3 Correct 1 ms 1484 KB Output is correct
4 Correct 1 ms 1484 KB Output is correct
5 Correct 1 ms 1484 KB Output is correct
6 Correct 2 ms 1484 KB Output is correct
7 Correct 2 ms 1612 KB Output is correct
8 Correct 4 ms 1612 KB Output is correct
9 Correct 3 ms 1612 KB Output is correct
10 Correct 38 ms 5736 KB Output is correct
11 Correct 68 ms 6752 KB Output is correct
12 Correct 111 ms 8092 KB Output is correct
13 Correct 125 ms 8516 KB Output is correct
14 Correct 98 ms 7332 KB Output is correct
15 Correct 67 ms 5220 KB Output is correct
16 Correct 62 ms 5068 KB Output is correct
17 Correct 832 ms 6840 KB Output is correct
18 Correct 1 ms 1484 KB Output is correct
19 Correct 1 ms 1484 KB Output is correct
20 Correct 1 ms 1484 KB Output is correct
21 Correct 1 ms 1484 KB Output is correct
22 Correct 1 ms 1484 KB Output is correct
23 Correct 5 ms 1676 KB Output is correct
24 Correct 5 ms 1704 KB Output is correct
25 Correct 8 ms 1684 KB Output is correct
26 Correct 7 ms 1740 KB Output is correct
27 Correct 387 ms 5904 KB Output is correct
28 Correct 1591 ms 8288 KB Output is correct
29 Correct 1673 ms 8700 KB Output is correct
30 Correct 1106 ms 9284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1203 ms 6084 KB Output is correct
2 Correct 1 ms 1484 KB Output is correct
3 Correct 1 ms 1484 KB Output is correct
4 Correct 1 ms 1484 KB Output is correct
5 Correct 4 ms 1612 KB Output is correct
6 Correct 3 ms 1612 KB Output is correct
7 Correct 3 ms 1612 KB Output is correct
8 Correct 1032 ms 6080 KB Output is correct
9 Correct 952 ms 6008 KB Output is correct
10 Correct 321 ms 4532 KB Output is correct
11 Correct 48 ms 7064 KB Output is correct
12 Correct 1 ms 1484 KB Output is correct
13 Correct 1 ms 1484 KB Output is correct
14 Correct 1 ms 1484 KB Output is correct
15 Correct 1 ms 1484 KB Output is correct
16 Correct 1 ms 1484 KB Output is correct
17 Correct 6 ms 1888 KB Output is correct
18 Correct 6 ms 1868 KB Output is correct
19 Correct 26 ms 6084 KB Output is correct
20 Correct 65 ms 8444 KB Output is correct
21 Correct 49 ms 7108 KB Output is correct
22 Correct 36 ms 6580 KB Output is correct
23 Correct 63 ms 7896 KB Output is correct
24 Correct 39 ms 5828 KB Output is correct
25 Correct 32 ms 5196 KB Output is correct
26 Correct 32 ms 5152 KB Output is correct
27 Correct 1 ms 1484 KB Output is correct
28 Correct 1 ms 1484 KB Output is correct
29 Correct 1 ms 1484 KB Output is correct
30 Correct 1 ms 1484 KB Output is correct
31 Correct 1 ms 1484 KB Output is correct
32 Correct 2 ms 1484 KB Output is correct
33 Correct 2 ms 1612 KB Output is correct
34 Correct 4 ms 1612 KB Output is correct
35 Correct 3 ms 1612 KB Output is correct
36 Correct 38 ms 5736 KB Output is correct
37 Correct 68 ms 6752 KB Output is correct
38 Correct 111 ms 8092 KB Output is correct
39 Correct 125 ms 8516 KB Output is correct
40 Correct 98 ms 7332 KB Output is correct
41 Correct 67 ms 5220 KB Output is correct
42 Correct 62 ms 5068 KB Output is correct
43 Correct 832 ms 6840 KB Output is correct
44 Correct 1 ms 1484 KB Output is correct
45 Correct 1 ms 1484 KB Output is correct
46 Correct 1 ms 1484 KB Output is correct
47 Correct 1 ms 1484 KB Output is correct
48 Correct 1 ms 1484 KB Output is correct
49 Correct 5 ms 1676 KB Output is correct
50 Correct 5 ms 1704 KB Output is correct
51 Correct 8 ms 1684 KB Output is correct
52 Correct 7 ms 1740 KB Output is correct
53 Correct 387 ms 5904 KB Output is correct
54 Correct 1591 ms 8288 KB Output is correct
55 Correct 1673 ms 8700 KB Output is correct
56 Correct 1106 ms 9284 KB Output is correct
57 Execution timed out 3079 ms 11132 KB Time limit exceeded
58 Halted 0 ms 0 KB -