Submission #62791

#TimeUsernameProblemLanguageResultExecution timeMemory
62791BBang3화살표 그리기 (KOI18_arrowH)C++14
100 / 100
81 ms16488 KiB
#include <cstdio> #include <algorithm> #include <math.h> #include <vector> using namespace std; int N; vector<int> P[100000 + 5]; int main() { scanf("%d", &N); for (int i = 1; i <= N; i++) { int pos, color; scanf("%d %d", &pos, &color); P[color].push_back(pos); } for (int i = 1; i <= N; i++) { sort(P[i].begin(), P[i].end()); } long long ans = 0; for (int i = 1; i <= N; i++) { if (P[i].size() <= 1) continue; for (int j = 0; j < P[i].size(); j++) { if (j == 0) ans += abs(P[i][j] - P[i][j + 1]); else if (j == P[i].size() - 1) ans += abs(P[i][j] - P[i][j - 1]); else ans += min(abs(P[i][j] - P[i][j - 1]), abs(P[i][j] - P[i][j + 1])); } } printf("%lld", ans); return 0; }

Compilation message (stderr)

arrow.cpp: In function 'int main()':
arrow.cpp:27:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int j = 0; j < P[i].size(); j++)
                   ~~^~~~~~~~~~~~~
arrow.cpp:30:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    else if (j == P[i].size() - 1) ans += abs(P[i][j] - P[i][j - 1]);
             ~~^~~~~~~~~~~~~~~~~~
arrow.cpp:11:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
  ~~~~~^~~~~~~~~~
arrow.cpp:15:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &pos, &color);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...