답안 #723800

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
723800 2023-04-14T10:26:12 Z kkts Pinball (JOI14_pinball) C++17
100 / 100
239 ms 14520 KB
#include<bits/stdc++.h>
#define f first
#define s second
#define int long long
#define pii pair<int,int>
using namespace std;
const int N = 3e5 + 5, mod = 1e9 + 7; // !
int tl[N], tr[N], M;
int getl(int id) {
    int mn = 1e18;
    for(id; id <= M; id += id & (-id)) mn = min(mn, tl[id]);
    return mn;
}
int getr(int id) {
    int mn = 1e18;
    for(id; id >= 1; id -= id & (-id)) mn = min(mn, tr[id]);
    return mn;
}
void updl(int id, int val) {
    for(id; id >= 1; id -= id & (-id)) tl[id]= min(tl[id], val);
}
void updr(int id, int val) {
    for(id; id <= M; id += id & (-id)) tr[id] = min(tr[id], val);
}
main(){
    int m, n;
    cin >> m >> n;
    vector<int> a(m + 2), b(m + 2), c(m + 2), d(m + 2);
    vector<int> x;
    for(int i = 1; i <= m; i++) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        x.push_back(a[i]);
        x.push_back(b[i]);
        x.push_back(c[i]);
    }
    x.push_back(1);
    x.push_back(n);
    sort(x.begin(), x.end());
    x.erase(unique(x.begin(), x.end()), x.end());
    M = x.size();
    for(int i = 1; i <= M; i++) tl[i] = tr[i] = 1e18;
    int ans = 1e18;
    updl(1, 0);
    updr(x.size(), 0);
    for(int i = 1; i <= m; i++) {
        a[i] = lower_bound(x.begin(), x.end(), a[i]) - x.begin() + 1;
        b[i] = lower_bound(x.begin(), x.end(), b[i]) - x.begin() + 1;
        c[i] = lower_bound(x.begin(), x.end(), c[i]) - x.begin() + 1;

        int L = getl(a[i]), R = getr(b[i]);
        ans = min(ans, L + R + d[i]);
        updl(c[i], L + d[i]);
        updr(c[i], R + d[i]);
    }
    cout << (ans == 1e18 ? -1 : ans);
 }

Compilation message

pinball.cpp: In function 'long long int getl(long long int)':
pinball.cpp:11:9: warning: statement has no effect [-Wunused-value]
   11 |     for(id; id <= M; id += id & (-id)) mn = min(mn, tl[id]);
      |         ^~
pinball.cpp: In function 'long long int getr(long long int)':
pinball.cpp:16:9: warning: statement has no effect [-Wunused-value]
   16 |     for(id; id >= 1; id -= id & (-id)) mn = min(mn, tr[id]);
      |         ^~
pinball.cpp: In function 'void updl(long long int, long long int)':
pinball.cpp:20:9: warning: statement has no effect [-Wunused-value]
   20 |     for(id; id >= 1; id -= id & (-id)) tl[id]= min(tl[id], val);
      |         ^~
pinball.cpp: In function 'void updr(long long int, long long int)':
pinball.cpp:23:9: warning: statement has no effect [-Wunused-value]
   23 |     for(id; id <= M; id += id & (-id)) tr[id] = min(tr[id], val);
      |         ^~
pinball.cpp: At global scope:
pinball.cpp:25:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   25 | main(){
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 3 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 3 ms 340 KB Output is correct
20 Correct 2 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 3 ms 340 KB Output is correct
24 Correct 3 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 3 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 3 ms 340 KB Output is correct
20 Correct 2 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 3 ms 340 KB Output is correct
24 Correct 3 ms 340 KB Output is correct
25 Correct 20 ms 1244 KB Output is correct
26 Correct 56 ms 2608 KB Output is correct
27 Correct 154 ms 5740 KB Output is correct
28 Correct 188 ms 7612 KB Output is correct
29 Correct 110 ms 4556 KB Output is correct
30 Correct 218 ms 7632 KB Output is correct
31 Correct 221 ms 8484 KB Output is correct
32 Correct 218 ms 7692 KB Output is correct
33 Correct 38 ms 2380 KB Output is correct
34 Correct 104 ms 5436 KB Output is correct
35 Correct 202 ms 10480 KB Output is correct
36 Correct 239 ms 14388 KB Output is correct
37 Correct 230 ms 14520 KB Output is correct
38 Correct 229 ms 14412 KB Output is correct