Submission #140584

#TimeUsernameProblemLanguageResultExecution timeMemory
140584khrbuddy03화살표 그리기 (KOI18_arrowH)C++14
100 / 100
48 ms6008 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int inf = 1e5 + 9;

vector<ll> arr[inf];

int main()  {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n; cin >> n;
    for (int i = 0; i < n; i++) {
        int x, y; cin >> x >> y;
        arr[y].push_back(x);
    }
    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        sort(arr[i].begin(), arr[i].end());
        if (arr[i].size() == 1 || arr[i].size() == 0) continue;
        else {
            for (int j = 1; j < arr[i].size() - 1; j++) {
                ans += min(arr[i][j] - arr[i][j - 1], arr[i][j + 1] - arr[i][j]);
            }
            ans += (arr[i][arr[i].size() - 1] - arr[i][arr[i].size() - 2]) + (arr[i][1] - arr[i][0]);
        }
    }
    cout << ans << '\n';
}

Compilation message (stderr)

arrow.cpp: In function 'int main()':
arrow.cpp:24:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (int j = 1; j < arr[i].size() - 1; j++) {
                             ~~^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...