답안 #659088

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
659088 2022-11-16T13:07:51 Z Jeff12345121 전차 (CEOI13_tram) C++14
45 / 100
1000 ms 1036 KB
#include <bits/stdc++.h>
#define REP(i,n) for(int i = 1; i <= (n); i++)
using namespace std;

#ifdef LOCAL
ifstream in("in.in");
ofstream out("out.out");
#else
#define in cin
#define out cout
#endif

///brute

int n,m;
const int nmax = 150005,inf = 1000000005;
pair<int,int> queries[nmax];
int a[nmax][3];
set<int> s[2];
int squared(int x) {
    return x * x;
}
int find_distance(int y, int x, int i, int j) {
    return squared(y - i) + squared(x - j);
}
int get_dis(int y, int x) {
    int val[3] = {inf,inf,inf};///min dis from some other value
    for (int k = 1; k <= 2; k++) {
        auto after = s[k - 1].lower_bound(y);
        auto before = after;
        if (before != s[k - 1].begin()) {
            before--;
            val[k] = min(val[k], find_distance(k , *before , x, y));
        }
        if (after != s[k - 1].end()) {
            val[k] = min(val[k], find_distance(k , *after , x, y));
        }
    }
    return min(val[1] ,val[2]);
}
pair<int,int> add() {
    pair<int,int> sol;
    int max_dis = -inf;

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= 2; j++) {
            if (a[i][j] == 1) continue;

            int dis = get_dis(i,j);
            if (dis > max_dis) {
                max_dis = dis;
                sol = {i,j};
            }
        }
    }

    return sol;
}
int main() {
    in >> n >> m;
    for (int i = 1; i <= m; i++) {
        char type;
        in >> type;
        if (type == 'E') {
            pair<int,int> pos = add();
            out << pos.first << " " << pos.second << "\n";
            a[pos.first][pos.second] = 1;
            s[pos.second - 1].insert(pos.first);
            queries[i] = pos;
        } else {
            int pos;
            in >> pos;
            s[queries[pos].second - 1].erase(queries[pos].first);

            a[queries[pos].first][queries[pos].second] = 0;           
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 207 ms 348 KB Output is correct
2 Correct 5 ms 312 KB Output is correct
3 Correct 102 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 215 ms 468 KB Output is correct
2 Correct 5 ms 468 KB Output is correct
3 Correct 85 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1090 ms 900 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1082 ms 1036 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1081 ms 580 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1050 ms 892 KB Time limit exceeded
2 Halted 0 ms 0 KB -