Submission #242904

#TimeUsernameProblemLanguageResultExecution timeMemory
242904MatesV13Svjetlost (COI18_svjetlost)C++11
40 / 100
3031 ms6136 KiB
#include <bits/stdc++.h> using namespace std; long long n, q, V, x[100005], y[100005], prijasnji[100005]; void update(int vrh){ int minus=0; for (int i=1; i<vrh; i++){ if (prijasnji[i]) minus++; } prijasnji[vrh]++; vrh-=minus; for (int i=vrh+1; i<=n; i++){ x[i-1]=x[i]; y[i-1]=y[i]; } return; } bool ok (int idx1, int idx2){ idx1 = (idx1+n-1)%n+1; idx2 = (idx2+n-1)%n+1; long long dx1 = x[idx1] - x[idx1-1]; long long dy1 = y[idx1] - y[idx1-1]; long long dx2 = x[idx2] - x[idx2-1]; long long dy2 = y[idx2] - y[idx2-1]; // cout << dx1 << " " << dy1 << " " << dx2 << " " << dy2 << endl; // cout << dx1*dy2 << " " << dx2*dy1 << endl; return (dx1*dy2 > dx2*dy1); } long double leng(int idx){ idx = (idx+n-1)%n+1; long long dx = x[idx] - x[idx-1]; long long dy = y[idx] - y[idx-1]; // cout << "duljina izmedu " << idx << " i " << idx-1 << " iznosi: " << sqrtl(dx*dx + dy*dy) << endl; return sqrtl(dx*dx + dy*dy); } long double dp[200005]; void check(){ long double ans=0.0000000000; x[0]=x[n]; y[0]=y[n]; int cur=1; dp[1] = leng(1); ans=dp[1]; // cout << "pomoc: 1 1" << endl << "udaljenost: " << dp[1] << endl << "ans: " << ans << endl << endl; for (int i=2; i<=2*n; i++){ while (!ok(cur, i)) cur++; // cout << "pomoc: " << i << " " << cur << endl; dp[i] = dp[i-1] + leng(i); // cout << "udaljenost: " << dp[i] << endl; ans = max(ans, dp[i] - dp[cur-1]); // cout << "ans: " << ans << endl << endl; } cout << ans << endl; return; } int main (){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i=1; i<=n; i++){ cin >> x[i] >> y[i]; } cout << fixed << setprecision(10); check(); cin >> q; while (q--){ cin >> V; update(V); n--; check(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...