Submission #64201

# Submission time Handle Problem Language Result Execution time Memory
64201 2018-08-03T13:37:38 Z gs14004 None (KOI18_arrowH) C++17
100 / 100
103 ms 21192 KB
#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

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 time Memory Grader output
1 Correct 12 ms 7416 KB Output is correct
2 Correct 13 ms 7512 KB Output is correct
3 Correct 13 ms 7512 KB Output is correct
4 Correct 12 ms 7512 KB Output is correct
5 Correct 10 ms 7512 KB Output is correct
6 Correct 13 ms 7512 KB Output is correct
7 Correct 14 ms 7512 KB Output is correct
8 Correct 12 ms 7576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 7416 KB Output is correct
2 Correct 13 ms 7512 KB Output is correct
3 Correct 13 ms 7512 KB Output is correct
4 Correct 12 ms 7512 KB Output is correct
5 Correct 10 ms 7512 KB Output is correct
6 Correct 13 ms 7512 KB Output is correct
7 Correct 14 ms 7512 KB Output is correct
8 Correct 12 ms 7576 KB Output is correct
9 Correct 13 ms 7620 KB Output is correct
10 Correct 11 ms 7688 KB Output is correct
11 Correct 12 ms 7708 KB Output is correct
12 Correct 12 ms 7724 KB Output is correct
13 Correct 11 ms 7772 KB Output is correct
14 Correct 14 ms 7776 KB Output is correct
15 Correct 12 ms 7928 KB Output is correct
16 Correct 12 ms 7928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 7416 KB Output is correct
2 Correct 13 ms 7512 KB Output is correct
3 Correct 13 ms 7512 KB Output is correct
4 Correct 12 ms 7512 KB Output is correct
5 Correct 10 ms 7512 KB Output is correct
6 Correct 13 ms 7512 KB Output is correct
7 Correct 14 ms 7512 KB Output is correct
8 Correct 12 ms 7576 KB Output is correct
9 Correct 13 ms 7620 KB Output is correct
10 Correct 11 ms 7688 KB Output is correct
11 Correct 12 ms 7708 KB Output is correct
12 Correct 12 ms 7724 KB Output is correct
13 Correct 11 ms 7772 KB Output is correct
14 Correct 14 ms 7776 KB Output is correct
15 Correct 12 ms 7928 KB Output is correct
16 Correct 12 ms 7928 KB Output is correct
17 Correct 19 ms 7984 KB Output is correct
18 Correct 14 ms 8108 KB Output is correct
19 Correct 17 ms 8224 KB Output is correct
20 Correct 17 ms 8332 KB Output is correct
21 Correct 15 ms 8476 KB Output is correct
22 Correct 17 ms 8604 KB Output is correct
23 Correct 19 ms 8696 KB Output is correct
24 Correct 17 ms 8844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 7416 KB Output is correct
2 Correct 13 ms 7512 KB Output is correct
3 Correct 13 ms 7512 KB Output is correct
4 Correct 12 ms 7512 KB Output is correct
5 Correct 10 ms 7512 KB Output is correct
6 Correct 13 ms 7512 KB Output is correct
7 Correct 14 ms 7512 KB Output is correct
8 Correct 12 ms 7576 KB Output is correct
9 Correct 13 ms 7620 KB Output is correct
10 Correct 11 ms 7688 KB Output is correct
11 Correct 12 ms 7708 KB Output is correct
12 Correct 12 ms 7724 KB Output is correct
13 Correct 11 ms 7772 KB Output is correct
14 Correct 14 ms 7776 KB Output is correct
15 Correct 12 ms 7928 KB Output is correct
16 Correct 12 ms 7928 KB Output is correct
17 Correct 19 ms 7984 KB Output is correct
18 Correct 14 ms 8108 KB Output is correct
19 Correct 17 ms 8224 KB Output is correct
20 Correct 17 ms 8332 KB Output is correct
21 Correct 15 ms 8476 KB Output is correct
22 Correct 17 ms 8604 KB Output is correct
23 Correct 19 ms 8696 KB Output is correct
24 Correct 17 ms 8844 KB Output is correct
25 Correct 103 ms 11668 KB Output is correct
26 Correct 69 ms 12256 KB Output is correct
27 Correct 90 ms 14192 KB Output is correct
28 Correct 74 ms 15252 KB Output is correct
29 Correct 81 ms 16952 KB Output is correct
30 Correct 79 ms 17944 KB Output is correct
31 Correct 76 ms 19436 KB Output is correct
32 Correct 85 ms 21192 KB Output is correct