Submission #234850

#TimeUsernameProblemLanguageResultExecution timeMemory
234850jhnah917화살표 그리기 (KOI18_arrowH)C++14
100 / 100
41 ms5624 KiB
#include <bits/stdc++.h> #define x first #define y second #define all(v) v.begin(), v.end() using namespace std; typedef long long ll; typedef pair<ll, ll> p; int n; vector<int> v[101010]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for(int i=0; i<n; i++){ int a, b; cin >> a >> b; v[b].push_back(a); } ll ans = 0; for(int i=0; i<101010; i++){ sort(all(v[i])); if(v[i].size() <= 1) continue; for(int j=0; j<v[i].size(); j++){ if(j == 0) ans += v[i][1] - v[i][j]; else if(j == v[i].size() - 1) ans += v[i][j] - v[i][j-1]; else ans += min(v[i][j] - v[i][j-1], v[i][j+1] - v[i][j]); } } cout << ans; }

Compilation message (stderr)

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