답안 #258693

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
258693 2020-08-06T11:39:33 Z dolphingarlic 전차 (CEOI13_tram) C++14
25 / 100
1000 ms 1064 KB
/*
CEOI 2013 Tram
- Medians
*/

#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

int n, m;
bool used[150001][3];
pair<int, int> pos[30001];
set<int> interesting;

ll dist(pair<int, int> A, pair<int, int> B) {
    return ll(B.first - A.first) * ll(B.first - A.first) + ll(B.second - A.second) * ll(B.second - A.second);
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    interesting.insert(1);
    interesting.insert(n);
    for (int i = 1; i <= m; i++) {
        char c;
        cin >> c;
        if (c == 'E') {
            // for (int j : interesting) cout << j << ' ';
            // cout << ": ";
            ll best_dist = 0;
            pair<int, int> best_pos;

            for (auto it = next(interesting.begin()); it != interesting.end(); it++) {
                int mid = (*it + *prev(it)) / 2;
                vector<pair<int, int>> cand = {{*prev(it), 1}, {*prev(it), 2}, {mid, 1}, {mid, 2}, {mid + 1, 1}, {mid + 1, 2}, {*it, 1}, {*it, 2}};
                for (pair<int, int> j : cand) {
                    ll d = LLONG_MAX;
                    for (pair<int, int> k : cand) {
                        if (used[k.first][k.second]) {
                            d = min(d, dist(j, k));
                        }
                    }
                    if (d > best_dist) {
                        best_dist = d;
                        best_pos = j;
                    }
                }
            }

            pos[i] = best_pos;
            used[pos[i].first][pos[i].second] = true;
            interesting.insert(pos[i].first);
            cout << pos[i].first << ' ' << pos[i].second << '\n';
        } else {
            int idx;
            cin >> idx;
            used[pos[idx].first][pos[idx].second] = false;
            if (pos[idx].first != 1 && pos[idx].first != n && !(used[pos[idx].first][0] || used[pos[idx].first][1]))
                interesting.erase(pos[idx].first);
        }
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 190 ms 492 KB Output is correct
2 Incorrect 11 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 192 ms 492 KB Output is correct
2 Incorrect 13 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 189 ms 912 KB Output is correct
2 Incorrect 18 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 178 ms 912 KB Output is correct
2 Incorrect 13 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1090 ms 644 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1095 ms 1064 KB Time limit exceeded
2 Halted 0 ms 0 KB -