Submission #611480

# Submission time Handle Problem Language Result Execution time Memory
611480 2022-07-29T05:14:53 Z 반딧불(#8497) Segway (COI19_segway) C++17
100 / 100
413 ms 142976 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

struct dat{
    int num, pos, t, accel;
    dat(){}
    dat(int num, int pos, int t, int accel): num(num), pos(pos), t(t), accel(accel){}
    bool operator<(const dat &r)const{
        if(t!=r.t) return t>r.t;
        return pos<r.pos;
    }
};

struct Fenwiwck{
    const int n = 600;
    int tree[602];

    void init(){
        for(int i=0; i<=n; i++) tree[i] = 0;
    }

    void add(int x, int v){
        if(!x) return;
        while(x<=n){
            tree[x] += v;
            x += x&-x;
        }
    }

    int sum(int x){
        int ret = 0;
        while(x){
            ret += tree[x];
            x -= x&-x;
        }
        return ret;
    }

    int sum(int l, int r){
        return sum(r) - sum(l-1);
    }
} tree;

int n, k;
int speed[20002][3];
bool accel[302];
int ans[20002];
int pos[20002];
vector<dat> datVec[1000002];

priority_queue<dat> pq;

int main(){
    scanf("%d", &n);
    for(int i=1; i<=n; i++) for(int j=0; j<3; j++) scanf("%d", &speed[i][j]);
    scanf("%d", &k);
    for(int i=1; i<=k; i++){
        int x;
        scanf("%d", &x);
        accel[x] = 1;
    }
    tree.init();

    for(int i=1; i<=n; i++){
        pos[i] = 0;
        datVec[0].push_back(dat(i, 0, 0, 0));
        tree.add(pos[i]*2, 1);
    }
    for(int nowT = 0; nowT <= 1000000; nowT++){
        for(dat tmp: datVec[nowT]){
            if(nowT){
                tree.add(tmp.pos * 2 - 1, -1);
                pos[tmp.num] = tmp.pos;
                tree.add(tmp.pos * 2, 1);
            }
        }

        vector<dat> nextVec;
        for(dat p: datVec[nowT]){
            int x = p.num, loc = p.pos, acc = p.accel, t = p.t;
//            printf("(%d %d %d %d)\n", x, loc, acc, t);
            if(loc==300){
                ans[x] = t;
                continue;
            }

            int nextSpeed, nextAcc;
            if(acc) nextSpeed = 1, nextAcc = acc-1;
            else if(accel[loc]){
                int tmp = tree.sum(loc*2+1, 600) % 20;
                if(tmp) nextSpeed = 1, nextAcc = tmp-1;
                else nextAcc = 0, nextSpeed = (loc<100 ? speed[x][0] : loc<200 ? speed[x][1] : speed[x][2]);
            }
            else nextAcc = 0, nextSpeed = (loc<100 ? speed[x][0] : loc<200 ? speed[x][1] : speed[x][2]);
            nextVec.push_back(dat(x, loc+1, t+nextSpeed, nextAcc));
        }

        for(dat p: nextVec){
            tree.add(p.pos * 2 - 2, -1);
            tree.add(p.pos * 2 - 1, 1);
            datVec[p.t].push_back(p);
        }
    }

    for(int i=1; i<=n; i++) printf("%d\n", ans[i]);
}

Compilation message

segway.cpp: In function 'int main()':
segway.cpp:57:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
segway.cpp:58:57: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |     for(int i=1; i<=n; i++) for(int j=0; j<3; j++) scanf("%d", &speed[i][j]);
      |                                                    ~~~~~^~~~~~~~~~~~~~~~~~~~
segway.cpp:59:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |     scanf("%d", &k);
      |     ~~~~~^~~~~~~~~~
segway.cpp:62:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |         scanf("%d", &x);
      |         ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 20 ms 23764 KB Output is correct
2 Correct 28 ms 25180 KB Output is correct
3 Correct 41 ms 29248 KB Output is correct
4 Correct 80 ms 43848 KB Output is correct
5 Correct 399 ms 142976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 23808 KB Output is correct
2 Correct 23 ms 23908 KB Output is correct
3 Correct 17 ms 23764 KB Output is correct
4 Correct 18 ms 23796 KB Output is correct
5 Correct 18 ms 24040 KB Output is correct
6 Correct 21 ms 24148 KB Output is correct
7 Correct 20 ms 24432 KB Output is correct
8 Correct 28 ms 24952 KB Output is correct
9 Correct 30 ms 25328 KB Output is correct
10 Correct 26 ms 25804 KB Output is correct
11 Correct 26 ms 25556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 23764 KB Output is correct
2 Correct 28 ms 25180 KB Output is correct
3 Correct 41 ms 29248 KB Output is correct
4 Correct 80 ms 43848 KB Output is correct
5 Correct 399 ms 142976 KB Output is correct
6 Correct 18 ms 23808 KB Output is correct
7 Correct 23 ms 23908 KB Output is correct
8 Correct 17 ms 23764 KB Output is correct
9 Correct 18 ms 23796 KB Output is correct
10 Correct 18 ms 24040 KB Output is correct
11 Correct 21 ms 24148 KB Output is correct
12 Correct 20 ms 24432 KB Output is correct
13 Correct 28 ms 24952 KB Output is correct
14 Correct 30 ms 25328 KB Output is correct
15 Correct 26 ms 25804 KB Output is correct
16 Correct 26 ms 25556 KB Output is correct
17 Correct 45 ms 30660 KB Output is correct
18 Correct 53 ms 35212 KB Output is correct
19 Correct 198 ms 71376 KB Output is correct
20 Correct 249 ms 90816 KB Output is correct
21 Correct 340 ms 102844 KB Output is correct
22 Correct 413 ms 123980 KB Output is correct
23 Correct 357 ms 120544 KB Output is correct