Submission #624581

# Submission time Handle Problem Language Result Execution time Memory
624581 2022-08-08T13:43:52 Z iomoon191 None (KOI18_arrowH) C++17
100 / 100
35 ms 8160 KB
#include <bits/stdc++.h>
using ll = long long;
#define int ll
using namespace std;

#define sz(x) (int)(x).size()
#define foru(i, l, r) for(int i = l; i <= r; i++)
#define ford(i, l, r) for(int i = l; i >= r; i--)
#define fi first
#define se second
#define mod 998244353

#define db(x) cerr << __LINE__ << " " << #x << " " << x << "\n"
using vi = vector<int>;
using pi = pair<int, int>;

const ll N = 200005;
const ll inf = 1e18;

int n;
vi adj[N];

int calc(vi v){
	int res = 0;
	if(sz(v) < 2) return 0;
	foru(i, 0, sz(v) - 1){
		int mn = inf;
		if(i + 1 < sz(v)) mn = min(mn, v[i + 1] - v[i]);
		if(i != 0) mn = min(mn, v[i] - v[i - 1]);
		res += mn;
	}
	return res;
}

void solve(){
	cin >> n;
	foru(i, 0, n - 1){
		int x, y; cin >> x >> y;
		adj[y].push_back(x);
	}
	int res = 0;
	foru(i, 1, n){
		sort(adj[i].begin(), adj[i].end());
		res += calc(adj[i]);
	}
	cout << res;
}

signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	int t = 1;
	while(t--){
		solve();
	}
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 4 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 5028 KB Output is correct
8 Correct 3 ms 5020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 4 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 5028 KB Output is correct
8 Correct 3 ms 5020 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 4 ms 5040 KB Output is correct
11 Correct 3 ms 5076 KB Output is correct
12 Correct 3 ms 5076 KB Output is correct
13 Correct 3 ms 5032 KB Output is correct
14 Correct 3 ms 5040 KB Output is correct
15 Correct 3 ms 5076 KB Output is correct
16 Correct 3 ms 5068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 4 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 5028 KB Output is correct
8 Correct 3 ms 5020 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 4 ms 5040 KB Output is correct
11 Correct 3 ms 5076 KB Output is correct
12 Correct 3 ms 5076 KB Output is correct
13 Correct 3 ms 5032 KB Output is correct
14 Correct 3 ms 5040 KB Output is correct
15 Correct 3 ms 5076 KB Output is correct
16 Correct 3 ms 5068 KB Output is correct
17 Correct 5 ms 5220 KB Output is correct
18 Correct 5 ms 5204 KB Output is correct
19 Correct 5 ms 5164 KB Output is correct
20 Correct 5 ms 5256 KB Output is correct
21 Correct 5 ms 5164 KB Output is correct
22 Correct 5 ms 5144 KB Output is correct
23 Correct 5 ms 5300 KB Output is correct
24 Correct 6 ms 5288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 4 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 5028 KB Output is correct
8 Correct 3 ms 5020 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 4 ms 5040 KB Output is correct
11 Correct 3 ms 5076 KB Output is correct
12 Correct 3 ms 5076 KB Output is correct
13 Correct 3 ms 5032 KB Output is correct
14 Correct 3 ms 5040 KB Output is correct
15 Correct 3 ms 5076 KB Output is correct
16 Correct 3 ms 5068 KB Output is correct
17 Correct 5 ms 5220 KB Output is correct
18 Correct 5 ms 5204 KB Output is correct
19 Correct 5 ms 5164 KB Output is correct
20 Correct 5 ms 5256 KB Output is correct
21 Correct 5 ms 5164 KB Output is correct
22 Correct 5 ms 5144 KB Output is correct
23 Correct 5 ms 5300 KB Output is correct
24 Correct 6 ms 5288 KB Output is correct
25 Correct 32 ms 8160 KB Output is correct
26 Correct 25 ms 7508 KB Output is correct
27 Correct 29 ms 7908 KB Output is correct
28 Correct 24 ms 7408 KB Output is correct
29 Correct 35 ms 7884 KB Output is correct
30 Correct 25 ms 7328 KB Output is correct
31 Correct 24 ms 7500 KB Output is correct
32 Correct 29 ms 7884 KB Output is correct