Submission #85065

#TimeUsernameProblemLanguageResultExecution timeMemory
85065tjdgus4384화살표 그리기 (KOI18_arrowH)C++14
100 / 100
50 ms16324 KiB
#include<cstdio> #include<vector> #include<algorithm> using namespace std; vector<int> v[100001]; int main() { int x, n, c; long long ans = 0; scanf("%d", &n); for(int i = 0;i < n;i++) { scanf("%d %d", &x, &c); v[c].push_back(x); } for(int i = 1;i <= n;i++) { if(v[i].size() <= 1) continue; sort(v[i].begin(), v[i].end()); ans += v[i][1] - v[i][0]; for(int j = 1;j < v[i].size() - 1;j++) { ans += min(v[i][j] - v[i][j - 1], v[i][j + 1] - v[i][j]); } ans += v[i][v[i].size() - 1] - v[i][v[i].size() - 2]; } printf("%lld", ans); return 0; }

Compilation message (stderr)

arrow.cpp: In function 'int main()':
arrow.cpp:22:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j = 1;j < v[i].size() - 1;j++)
                       ~~^~~~~~~~~~~~~~~~~
arrow.cpp:11:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
arrow.cpp:14:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &x, &c);
         ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...