Submission #64201

#TimeUsernameProblemLanguageResultExecution timeMemory
64201gs14004화살표 그리기 (KOI18_arrowH)C++17
100 / 100
103 ms21192 KiB
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <functional>
#include <vector>
#include <numeric>
#include <deque>
#include <bitset>
#include <iostream>
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<int, int> pi;
const int MAXN = 300005;
const int mod = 1e9 + 7;

vector<int> v[MAXN];

lint solve(vector<int> &v){
	if(v.size() <= 1) return 0;
	lint ret = 0;
	for(int i=0; i<v.size(); i++){
		int ans = 1e9;
		if(i + 1 < v.size()) ans = min(ans, v[i+1] - v[i]);
		if(i > 0) ans = min(ans, v[i] - v[i-1]);
		ret += ans;
	}
	return ret;
}

int main(){
	int n;
	scanf("%d",&n);
	for(int i=0; i<n; i++){
		int x, y;
		scanf("%d %d",&x,&y);
		v[y].push_back(x);
	}
	lint ans = 0;
	for(int i=1; i<=n;i++){
		sort(v[i].begin(), v[i].end());
		ans += solve(v[i]);
	}
	cout << ans << endl;
}

Compilation message (stderr)

arrow.cpp: In function 'lint solve(std::vector<int>&)':
arrow.cpp:30:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<v.size(); i++){
               ~^~~~~~~~~
arrow.cpp:32:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(i + 1 < v.size()) ans = min(ans, v[i+1] - v[i]);
      ~~~~~~^~~~~~~~~~
arrow.cpp: In function 'int main()':
arrow.cpp:41:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
  ~~~~~^~~~~~~~~
arrow.cpp:44:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d",&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...