Submission #159072

#TimeUsernameProblemLanguageResultExecution timeMemory
159072dennisstar화살표 그리기 (KOI18_arrowH)C++11
100 / 100
50 ms5496 KiB
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;

int N;
vector<int> ar[100010];

int main()
{
	scanf("%d", &N);
	int a, b;
	int i, j;
	for (i=0; i<N; i++) {
		scanf("%d %d", &a, &b);
		ar[b].push_back(a);
	}
	ll ans=0;
	for (i=1; i<=N; i++) {
		sort(ar[i].begin(), ar[i].end());
		for (j=0; j<ar[i].size(); j++) {
			a=(j?ar[i][j-1]:-(1<<30));
			b=(j<ar[i].size()-1?ar[i][j+1]:-(1<<30));
			ans+=(ll)((a==b&&a==-(1<<30))?0:min(abs(ar[i][j]-a), abs(ar[i][j]-b)));
		}
	}
	printf("%lld", ans);
	return 0;
}

Compilation message (stderr)

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