Submission #62791

# Submission time Handle Problem Language Result Execution time Memory
62791 2018-07-30T04:31:38 Z BBang3 None (KOI18_arrowH) C++14
100 / 100
81 ms 16488 KB
#include <cstdio>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;

int N;
vector<int> P[100000 + 5];
int main()
{
	scanf("%d", &N);
	for (int i = 1; i <= N; i++)
	{
		int pos, color;
		scanf("%d %d", &pos, &color);
		P[color].push_back(pos);
	}
	for (int i = 1; i <= N; i++)
	{
		sort(P[i].begin(), P[i].end());
	}

	long long ans = 0;
	for (int i = 1; i <= N; i++)
	{
		if (P[i].size() <= 1) continue;
		for (int j = 0; j < P[i].size(); j++)
		{
			if (j == 0) ans += abs(P[i][j] - P[i][j + 1]);
			else if (j == P[i].size() - 1) ans += abs(P[i][j] - P[i][j - 1]);
			else ans += min(abs(P[i][j] - P[i][j - 1]), abs(P[i][j] - P[i][j + 1]));
		}
	}
	printf("%lld", ans);
	return 0;
}

Compilation message

arrow.cpp: In function 'int main()':
arrow.cpp:27:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int j = 0; j < P[i].size(); j++)
                   ~~^~~~~~~~~~~~~
arrow.cpp:30:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    else if (j == P[i].size() - 1) ans += abs(P[i][j] - P[i][j - 1]);
             ~~^~~~~~~~~~~~~~~~~~
arrow.cpp:11:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
  ~~~~~^~~~~~~~~~
arrow.cpp:15:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &pos, &color);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2680 KB Output is correct
2 Correct 6 ms 2796 KB Output is correct
3 Correct 6 ms 2796 KB Output is correct
4 Correct 6 ms 2940 KB Output is correct
5 Correct 6 ms 2940 KB Output is correct
6 Correct 5 ms 2940 KB Output is correct
7 Correct 5 ms 2940 KB Output is correct
8 Correct 6 ms 3008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2680 KB Output is correct
2 Correct 6 ms 2796 KB Output is correct
3 Correct 6 ms 2796 KB Output is correct
4 Correct 6 ms 2940 KB Output is correct
5 Correct 6 ms 2940 KB Output is correct
6 Correct 5 ms 2940 KB Output is correct
7 Correct 5 ms 2940 KB Output is correct
8 Correct 6 ms 3008 KB Output is correct
9 Correct 6 ms 3008 KB Output is correct
10 Correct 5 ms 3008 KB Output is correct
11 Correct 5 ms 3120 KB Output is correct
12 Correct 6 ms 3120 KB Output is correct
13 Correct 7 ms 3120 KB Output is correct
14 Correct 7 ms 3120 KB Output is correct
15 Correct 8 ms 3120 KB Output is correct
16 Correct 7 ms 3120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2680 KB Output is correct
2 Correct 6 ms 2796 KB Output is correct
3 Correct 6 ms 2796 KB Output is correct
4 Correct 6 ms 2940 KB Output is correct
5 Correct 6 ms 2940 KB Output is correct
6 Correct 5 ms 2940 KB Output is correct
7 Correct 5 ms 2940 KB Output is correct
8 Correct 6 ms 3008 KB Output is correct
9 Correct 6 ms 3008 KB Output is correct
10 Correct 5 ms 3008 KB Output is correct
11 Correct 5 ms 3120 KB Output is correct
12 Correct 6 ms 3120 KB Output is correct
13 Correct 7 ms 3120 KB Output is correct
14 Correct 7 ms 3120 KB Output is correct
15 Correct 8 ms 3120 KB Output is correct
16 Correct 7 ms 3120 KB Output is correct
17 Correct 10 ms 3272 KB Output is correct
18 Correct 14 ms 3396 KB Output is correct
19 Correct 12 ms 3512 KB Output is correct
20 Correct 11 ms 3748 KB Output is correct
21 Correct 11 ms 3764 KB Output is correct
22 Correct 11 ms 3872 KB Output is correct
23 Correct 14 ms 4112 KB Output is correct
24 Correct 12 ms 4236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2680 KB Output is correct
2 Correct 6 ms 2796 KB Output is correct
3 Correct 6 ms 2796 KB Output is correct
4 Correct 6 ms 2940 KB Output is correct
5 Correct 6 ms 2940 KB Output is correct
6 Correct 5 ms 2940 KB Output is correct
7 Correct 5 ms 2940 KB Output is correct
8 Correct 6 ms 3008 KB Output is correct
9 Correct 6 ms 3008 KB Output is correct
10 Correct 5 ms 3008 KB Output is correct
11 Correct 5 ms 3120 KB Output is correct
12 Correct 6 ms 3120 KB Output is correct
13 Correct 7 ms 3120 KB Output is correct
14 Correct 7 ms 3120 KB Output is correct
15 Correct 8 ms 3120 KB Output is correct
16 Correct 7 ms 3120 KB Output is correct
17 Correct 10 ms 3272 KB Output is correct
18 Correct 14 ms 3396 KB Output is correct
19 Correct 12 ms 3512 KB Output is correct
20 Correct 11 ms 3748 KB Output is correct
21 Correct 11 ms 3764 KB Output is correct
22 Correct 11 ms 3872 KB Output is correct
23 Correct 14 ms 4112 KB Output is correct
24 Correct 12 ms 4236 KB Output is correct
25 Correct 81 ms 6876 KB Output is correct
26 Correct 56 ms 7560 KB Output is correct
27 Correct 72 ms 9380 KB Output is correct
28 Correct 53 ms 10384 KB Output is correct
29 Correct 79 ms 12088 KB Output is correct
30 Correct 57 ms 13212 KB Output is correct
31 Correct 66 ms 14508 KB Output is correct
32 Correct 78 ms 16488 KB Output is correct