Submission #63499

# Submission time Handle Problem Language Result Execution time Memory
63499 2018-08-02T04:03:18 Z kjp4155 None (KOI18_arrowH) C++17
100 / 100
92 ms 16836 KB
#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

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 time Memory Grader output
1 Correct 7 ms 2680 KB Output is correct
2 Correct 6 ms 2796 KB Output is correct
3 Correct 5 ms 2796 KB Output is correct
4 Correct 6 ms 2796 KB Output is correct
5 Correct 5 ms 2824 KB Output is correct
6 Correct 5 ms 2824 KB Output is correct
7 Correct 5 ms 2848 KB Output is correct
8 Correct 5 ms 2876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 2680 KB Output is correct
2 Correct 6 ms 2796 KB Output is correct
3 Correct 5 ms 2796 KB Output is correct
4 Correct 6 ms 2796 KB Output is correct
5 Correct 5 ms 2824 KB Output is correct
6 Correct 5 ms 2824 KB Output is correct
7 Correct 5 ms 2848 KB Output is correct
8 Correct 5 ms 2876 KB Output is correct
9 Correct 6 ms 2880 KB Output is correct
10 Correct 34 ms 2900 KB Output is correct
11 Correct 5 ms 2916 KB Output is correct
12 Correct 7 ms 2936 KB Output is correct
13 Correct 7 ms 3136 KB Output is correct
14 Correct 5 ms 3136 KB Output is correct
15 Correct 8 ms 3136 KB Output is correct
16 Correct 6 ms 3244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 2680 KB Output is correct
2 Correct 6 ms 2796 KB Output is correct
3 Correct 5 ms 2796 KB Output is correct
4 Correct 6 ms 2796 KB Output is correct
5 Correct 5 ms 2824 KB Output is correct
6 Correct 5 ms 2824 KB Output is correct
7 Correct 5 ms 2848 KB Output is correct
8 Correct 5 ms 2876 KB Output is correct
9 Correct 6 ms 2880 KB Output is correct
10 Correct 34 ms 2900 KB Output is correct
11 Correct 5 ms 2916 KB Output is correct
12 Correct 7 ms 2936 KB Output is correct
13 Correct 7 ms 3136 KB Output is correct
14 Correct 5 ms 3136 KB Output is correct
15 Correct 8 ms 3136 KB Output is correct
16 Correct 6 ms 3244 KB Output is correct
17 Correct 9 ms 3416 KB Output is correct
18 Correct 9 ms 3544 KB Output is correct
19 Correct 9 ms 3652 KB Output is correct
20 Correct 12 ms 3764 KB Output is correct
21 Correct 11 ms 3908 KB Output is correct
22 Correct 9 ms 4016 KB Output is correct
23 Correct 9 ms 4128 KB Output is correct
24 Correct 9 ms 4252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 2680 KB Output is correct
2 Correct 6 ms 2796 KB Output is correct
3 Correct 5 ms 2796 KB Output is correct
4 Correct 6 ms 2796 KB Output is correct
5 Correct 5 ms 2824 KB Output is correct
6 Correct 5 ms 2824 KB Output is correct
7 Correct 5 ms 2848 KB Output is correct
8 Correct 5 ms 2876 KB Output is correct
9 Correct 6 ms 2880 KB Output is correct
10 Correct 34 ms 2900 KB Output is correct
11 Correct 5 ms 2916 KB Output is correct
12 Correct 7 ms 2936 KB Output is correct
13 Correct 7 ms 3136 KB Output is correct
14 Correct 5 ms 3136 KB Output is correct
15 Correct 8 ms 3136 KB Output is correct
16 Correct 6 ms 3244 KB Output is correct
17 Correct 9 ms 3416 KB Output is correct
18 Correct 9 ms 3544 KB Output is correct
19 Correct 9 ms 3652 KB Output is correct
20 Correct 12 ms 3764 KB Output is correct
21 Correct 11 ms 3908 KB Output is correct
22 Correct 9 ms 4016 KB Output is correct
23 Correct 9 ms 4128 KB Output is correct
24 Correct 9 ms 4252 KB Output is correct
25 Correct 77 ms 7332 KB Output is correct
26 Correct 53 ms 8164 KB Output is correct
27 Correct 79 ms 10016 KB Output is correct
28 Correct 92 ms 10912 KB Output is correct
29 Correct 67 ms 12664 KB Output is correct
30 Correct 55 ms 13736 KB Output is correct
31 Correct 72 ms 14996 KB Output is correct
32 Correct 59 ms 16836 KB Output is correct