답안 #570092

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
570092 2022-05-28T14:23:19 Z davi_bart 이상적인 도시 (IOI12_city) C++17
23 / 100
47 ms 16584 KB
#pragma GCC optimize("O3")
#pragma GCC target("popcnt")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define fi first
#define se second
#define pb push_back
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
static const ll mod = 1e9;
int N;
vector<ll> v[100010];
map<ll, ll> ans[100010];
signed DistanceSum(signed n, signed *X, signed *Y) {
    N = n;
    int mi = X[0];
    for (int i = 0; i < N; i++) {
        mi = min(mi, (int)X[i]);
    }
    for (int i = 0; i < N; i++) {
        X[i] -= mi;
        v[X[i]].pb(Y[i]);
    }
    ll tot = 0;
    ll fatte = 0;
    for (int i = 0; i < N; i++) {
        if (v[i].size() == 0) break;
        sort(v[i].begin(), v[i].end());
        for (int j = 0; j < v[i].size(); j++) {
            ll prima = j;
            ll dopo = v[i].size() - j - 1;
            ans[i][v[i][j]] = prima * (prima + 1) / 2 + dopo * (dopo + 1) / 2;
            tot += dopo * (dopo + 1) / 2;
            if (i) {
                ll cur = v[i][j];
                cur = max(cur, v[i - 1][0]);
                cur = min(cur, v[i - 1].back());
                // cout << cur << " " << v[i][j] << " " << fatte << " " << ans[i - 1][cur] << endl;
                tot += (ll)(1 + abs(v[i][j] - cur)) * fatte + ans[i - 1][cur];
                ans[i][v[i][j]] += (ll)(1 + abs(v[i][j] - cur)) * fatte + ans[i - 1][cur];
            }
            ans[i][v[i][j]] %= mod;
            tot %= mod;
            // cout << i << " " << j << " " << ans[i][j] << endl;
        }
        // cout << i << " " << ans[i][0] << endl;
        fatte += v[i].size();
    }
    return tot;
}

Compilation message

city.cpp: In function 'int DistanceSum(int, int*, int*)':
city.cpp:30:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |         for (int j = 0; j < v[i].size(); j++) {
      |                         ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 7252 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 7380 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 9044 KB Output is correct
2 Correct 12 ms 9172 KB Output is correct
3 Correct 28 ms 11880 KB Output is correct
4 Correct 22 ms 11728 KB Output is correct
5 Correct 46 ms 16476 KB Output is correct
6 Correct 40 ms 16216 KB Output is correct
7 Correct 44 ms 16456 KB Output is correct
8 Correct 47 ms 16452 KB Output is correct
9 Correct 40 ms 15948 KB Output is correct
10 Correct 35 ms 16584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 14 ms 9428 KB Output isn't correct
2 Halted 0 ms 0 KB -