Submission #52489


ソースコード

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <bits/stdc++.h>
using namespace std;
template<class T>
struct SegmentTree {
int size;
T nullValue;
vector<T> data;
SegmentTree ( int n, T defaultValue, T nullValue) {
for ( size = 1; size < n; size *= 2 );
data.resize( 2*size-1, defaultValue);
this->nullValue = nullValue;
}
T marge ( T a, T b ) {
return max ( a, b );
}
void update ( int pos, T value ) {
pos += size-1;
data[pos] = value;
while ( pos > 0 ) {
pos = ( pos - 1 ) / 2;
data[pos] = marge( data[pos*2+1], data[pos*2+2] );
}
}
T get ( int begin, int end, int pos=0, int left=0, int right=-1 ) {
if ( right == -1 ) right = size;
if ( right <= begin || end <= left ) return nullValue;
if ( begin <= left && right <= end ) return data[pos];
int next = ( left + right ) / 2;
return marge(get ( begin, end, pos*2+1, left, next ), get ( begin, end, pos*2+2, next, right ));
}
inline const T& operator [] ( int index ) const {
return data[index+size-1];
}
inline T& operator [] ( int index ) {
return data[index+size-1];
}
};
signed main ( ) {
int w, h, n;
scanf("%d %d %d", &w, &h, &n);
SegmentTree<int> maxY(w+1, 0, 0);
for ( int i = 0; i < n; i++ ) {
int x, y;
scanf("%d %d", &x, &y);
if ( maxY[x] < y ) maxY.update(x, y);
}
int ans = 0x3f3f3f3f;
for ( int i = 0; i < w; i++ ) {
ans = min ( ans, maxY.get(i+1, w+1)+i );
}
cout << ans << endl;
return 0;
}

ステータス

項目 データ
問題 0962 - ダンジョン
ユーザー名 r1825
投稿日時 2019-08-05 21:30:44
言語 C++
状態 Accepted
得点 11
ソースコード長 1702 Byte
最大実行時間 53 ms
最大メモリ使用量 1704 KB

セット

セット 得点 Cases
1 ALL 11 / 11 *

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
in1.txt AC 21 ms 604 KB
1
in2.txt AC 22 ms 484 KB
1
in3.txt AC 23 ms 520 KB
1
in4.txt AC 22 ms 724 KB
1
in5.txt AC 15 ms 692 KB
1
in6.txt AC 23 ms 660 KB
1
in7.txt AC 19 ms 508 KB
1
in8.txt AC 24 ms 612 KB
1
in9.txt AC 17 ms 708 KB
1
in10.txt AC 17 ms 448 KB
1
in11.txt AC 18 ms 548 KB
1
in12.txt AC 20 ms 392 KB
1
in13.txt AC 23 ms 356 KB
1
in14.txt AC 17 ms 576 KB
1
in15.txt AC 19 ms 544 KB
1
in16.txt AC 20 ms 512 KB
1
in17.txt AC 16 ms 468 KB
1
in18.txt AC 44 ms 1576 KB
1
in19.txt AC 48 ms 1540 KB
1
in20.txt AC 50 ms 1612 KB
1
in21.txt AC 53 ms 1580 KB
1
in22.txt AC 46 ms 1548 KB
1
in23.txt AC 42 ms 1644 KB
1
in24.txt AC 20 ms 460 KB
1
in25.txt AC 52 ms 1580 KB
1
in26.txt AC 53 ms 1544 KB
1
in27.txt AC 41 ms 1512 KB
1
in28.txt AC 45 ms 1608 KB
1
in29.txt AC 36 ms 1704 KB
1
in30.txt AC 50 ms 1520 KB
1