답안 #784254

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
784254 2023-07-15T22:29:49 Z GordonRemzi007 송신탑 (IOI22_towers) C++17
11 / 100
4000 ms 2344 KB
#include <iostream>
#include <vector>
#include <algorithm>
 
using namespace std;
 
vector<int> a;
vector<bool> used;
vector<pair<int,int>> b;
bool srt(pair<int,int> a, pair<int,int> b) {
    return a.first < b.first;
}
void init(int n, vector<int> h) {
  	a = h;
  	used = vector<bool>(n, false);
	b = vector<pair<int,int>>(n);
	for(int i = 0; i < n; i++) b[i] = {a[i], i};
    sort(b.begin(), b.end(), srt);
}
int max_towers(int l, int r, int d) {
    int res = 0, f, s;
    bool ok;
  	used = vector<bool>(a.size(), false);
    for(int i = 0; i < a.size(); i++) {
		if(l > b[i].second || r < b[i].second) continue;
        f = b[i].second, s = b[i].second;
        ok = true;
        //find closest left and right a[i] >= a[b[i].second]+d
        for(; f >= l; f--) {
            if(used[f]) {
                ok = false;
                break;
            }
            if(a[f] >= a[b[i].second]+d) break;
            if(f == l) {
                f = b[i].second;
                break;
            }
        }
        for(; s <= r; s++) {
            if(used[s]) {
                ok = false;
                break;
            }
            if(a[s] >= a[b[i].second]+d) break;
            if(s == r) {
                s = b[i].second;
                break;
            }
        }
        if(ok) {
            used[b[i].second] = true;
            res++;
        }
    }
    return res;
}

Compilation message

towers.cpp: In function 'int max_towers(int, int, int)':
towers.cpp:24:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |     for(int i = 0; i < a.size(); i++) {
      |                    ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4067 ms 1372 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 208 KB Output is correct
19 Correct 1 ms 208 KB Output is correct
20 Correct 1 ms 208 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 3 ms 208 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 208 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 208 KB Output is correct
29 Correct 1 ms 208 KB Output is correct
30 Correct 1 ms 208 KB Output is correct
31 Correct 1 ms 208 KB Output is correct
32 Correct 4 ms 208 KB Output is correct
33 Correct 4 ms 208 KB Output is correct
34 Correct 5 ms 336 KB Output is correct
35 Correct 1 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 208 KB Output is correct
19 Correct 1 ms 208 KB Output is correct
20 Correct 1 ms 208 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 3 ms 208 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 208 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 208 KB Output is correct
29 Correct 1 ms 208 KB Output is correct
30 Correct 1 ms 208 KB Output is correct
31 Correct 1 ms 208 KB Output is correct
32 Correct 4 ms 208 KB Output is correct
33 Correct 4 ms 208 KB Output is correct
34 Correct 5 ms 336 KB Output is correct
35 Correct 1 ms 208 KB Output is correct
36 Correct 13 ms 1588 KB Output is correct
37 Correct 24 ms 2344 KB Output is correct
38 Correct 19 ms 2192 KB Output is correct
39 Correct 21 ms 2208 KB Output is correct
40 Correct 19 ms 2256 KB Output is correct
41 Correct 23 ms 2224 KB Output is correct
42 Correct 25 ms 2264 KB Output is correct
43 Correct 2239 ms 2200 KB Output is correct
44 Correct 200 ms 2256 KB Output is correct
45 Correct 22 ms 2212 KB Output is correct
46 Correct 15 ms 2204 KB Output is correct
47 Correct 20 ms 2208 KB Output is correct
48 Correct 18 ms 2200 KB Output is correct
49 Correct 18 ms 2204 KB Output is correct
50 Correct 203 ms 2224 KB Output is correct
51 Correct 485 ms 2256 KB Output is correct
52 Correct 20 ms 2256 KB Output is correct
53 Correct 23 ms 2212 KB Output is correct
54 Correct 19 ms 2208 KB Output is correct
55 Execution timed out 4041 ms 2212 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4014 ms 2252 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4094 ms 720 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 208 KB Output is correct
19 Correct 1 ms 208 KB Output is correct
20 Correct 1 ms 208 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 3 ms 208 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 208 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 208 KB Output is correct
29 Correct 1 ms 208 KB Output is correct
30 Correct 1 ms 208 KB Output is correct
31 Correct 1 ms 208 KB Output is correct
32 Correct 4 ms 208 KB Output is correct
33 Correct 4 ms 208 KB Output is correct
34 Correct 5 ms 336 KB Output is correct
35 Correct 1 ms 208 KB Output is correct
36 Correct 13 ms 1588 KB Output is correct
37 Correct 24 ms 2344 KB Output is correct
38 Correct 19 ms 2192 KB Output is correct
39 Correct 21 ms 2208 KB Output is correct
40 Correct 19 ms 2256 KB Output is correct
41 Correct 23 ms 2224 KB Output is correct
42 Correct 25 ms 2264 KB Output is correct
43 Correct 2239 ms 2200 KB Output is correct
44 Correct 200 ms 2256 KB Output is correct
45 Correct 22 ms 2212 KB Output is correct
46 Correct 15 ms 2204 KB Output is correct
47 Correct 20 ms 2208 KB Output is correct
48 Correct 18 ms 2200 KB Output is correct
49 Correct 18 ms 2204 KB Output is correct
50 Correct 203 ms 2224 KB Output is correct
51 Correct 485 ms 2256 KB Output is correct
52 Correct 20 ms 2256 KB Output is correct
53 Correct 23 ms 2212 KB Output is correct
54 Correct 19 ms 2208 KB Output is correct
55 Execution timed out 4041 ms 2212 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4067 ms 1372 KB Time limit exceeded
2 Halted 0 ms 0 KB -