Submission #63499

#TimeUsernameProblemLanguageResultExecution timeMemory
63499kjp4155화살표 그리기 (KOI18_arrowH)C++17
100 / 100
92 ms16836 KiB
#include <stdio.h> #include <algorithm> #include <utility> #include <vector> using namespace std; typedef long long ll; int N; vector<ll> v[100500]; int main(){ scanf("%d",&N); for(int i=1;i<=N;i++){ ll x,y; scanf("%lld%lld",&x,&y); v[y].push_back(x); } ll ans = 0; // 각 색깔별로 점들을 정렬한 뒤, 각 점마다 가장 가까운 점까지의 거리를 답에 더한다 for(int i=1;i<=N;i++){ // 색 i에 점이 한 개 이하라면 넘어간다 if( v[i].size() <= 1 ) continue; sort(v[i].begin(), v[i].end()); // 색 i의 j번째 점을 처리 for(int j=0;j<v[i].size();j++){ ll mn = 1e18; if( j > 0 ) mn = min( mn, v[i][j]-v[i][j-1] ); if( j < v[i].size()-1 ) mn = min( mn, v[i][j+1]-v[i][j] ); ans += mn; } } printf("%lld\n",ans); }

Compilation message (stderr)

arrow.cpp: In function 'int main()':
arrow.cpp:30:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=0;j<v[i].size();j++){
               ~^~~~~~~~~~~~
arrow.cpp:33:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if( j < v[i].size()-1 ) mn = min( mn, v[i][j+1]-v[i][j] );
        ~~^~~~~~~~~~~~~~~
arrow.cpp:13:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&N);
  ~~~~~^~~~~~~~~
arrow.cpp:15:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   ll x,y; scanf("%lld%lld",&x,&y);
           ~~~~~^~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...