Submission #493703

# Submission time Handle Problem Language Result Execution time Memory
493703 2021-12-12T16:09:06 Z vulpes Countries (BOI06_countries) C++17
100 / 100
4 ms 348 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 1007;

struct country {
    int x, y, s, ind;
    bool operator<(country a) {
        return s > a.s ||
            (s == a.s && ind < a.ind);
    }
} a[N];

int dist(int i, int j) {
    return (a[i].x - a[j].x) * (a[i].x - a[j].x) +
           (a[i].y - a[j].y) * (a[i].y - a[j].y);
}

bool cmp() {

}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n; cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i].x >> a[i].y >> a[i].s;
        a[i].ind = i;
    }
    sort(a, a + n);
    vector<int> r(n);
    for (int i = 0; i < n; i++) {
        vector<int> v;
        for (int j = 0; j < i; j++) {
            if (a[j].s > a[i].s * dist(i, j)) {
                v.push_back(j);
            }
        }
        if (v.empty()) {
            r[a[i].ind] = 0; continue;
        }
        int h = v[0], c = 1;
        for (int j = 1; j < v.size(); j++) {
            int d1 = a[h].s * dist(v[j], i);
            int d2 = a[v[j]].s * dist(h, i);
            if (d1 == d2) {
                c++; continue;
            }
            if (d1 < d2) {
                h = v[j]; c = 1;
            }
        }
        if (c > 1) {
            r[a[i].ind] = -1; continue;
        }
        r[a[i].ind] = (r[a[h].ind] ? r[a[h].ind] : a[h].ind + 1);
    }
    for (int i = 0; i < n; i++) {
        if (r[i] > 0) {
            cout << r[i] << endl; continue;
        }
        cout << (r[i] ? "D" : "K") << endl;
    }
}

Compilation message

countries.cpp: In function 'bool cmp()':
countries.cpp:21:1: warning: no return statement in function returning non-void [-Wreturn-type]
   21 | }
      | ^
countries.cpp: In function 'int main()':
countries.cpp:44:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |         for (int j = 1; j < v.size(); j++) {
      |                         ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 2 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 3 ms 348 KB Output is correct
9 Correct 3 ms 332 KB Output is correct
10 Correct 3 ms 332 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 316 KB Output is correct
14 Correct 2 ms 332 KB Output is correct
15 Correct 1 ms 320 KB Output is correct
16 Correct 2 ms 320 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 4 ms 332 KB Output is correct
19 Correct 4 ms 332 KB Output is correct
20 Correct 3 ms 324 KB Output is correct