Submission #624581

#TimeUsernameProblemLanguageResultExecution timeMemory
624581iomoon191화살표 그리기 (KOI18_arrowH)C++17
100 / 100
35 ms8160 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...