Submission #949882

#TimeUsernameProblemLanguageResultExecution timeMemory
949882fuad27Alternating Current (BOI18_alternating)C++17
33 / 100
1559 ms2396 KiB
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("O3") mt19937 rng(chrono::steady_clock().now().time_since_epoch().count()); long double P(int old, int nw, long double temp) { if(nw < old)return 1.0; return exp((old-nw)/temp); } vector<int> mask; vector<pair<int,int>> a; int n, m; int eval() { int cnt1[n+1], cnt2[n+1]; memset(cnt1, 0, sizeof cnt1); memset(cnt2, 0, sizeof cnt2); for(int i = 0;i<m;i++) { if(mask[i]) { if(a[i].second>=a[i].first) { cnt1[a[i].first]++; cnt1[a[i].second+1]--; } else { cnt1[a[i].first]++; cnt1[0]++; cnt1[a[i].second+1]--; } } else { if(a[i].second>=a[i].first) { cnt2[a[i].first]++; cnt2[a[i].second+1]--; } else { cnt2[a[i].first]++; cnt2[0]++; cnt2[a[i].second+1]--; } } } for(int i = 1;i<=n;i++) { cnt1[i]+=cnt1[i-1]; cnt2[i]+=cnt2[i-1]; } int cc=0; for(int i = 0;i<n;i++) { if(cnt1[i]<=0)cc++; if(cnt2[i]<=0)cc++; } return cc; } int main () { cin.tie(0)->sync_with_stdio(0); cin >> n >> m; auto start=clock(); mask.resize(m); a.resize(m); for(int i = 0;i<m;i++){ cin >> a[i].first >> a[i].second; a[i].first--; a[i].second--; } while((long double)(clock()-start)/CLOCKS_PER_SEC < 1.5) { long double temp = 1000; for(int i = 0;i<m;i++)mask[i]=rng()%2; int old = eval(); for(int i = 0;i<10000;i++) { int c = rng()%m; mask[c]^=1; int nw = eval(); if(nw==0) { for(int i:mask)cout << i; cout << "\n"; return 0; } long double rn = (long double)(rng()%1000)/1000; if(P(old, nw, temp)>rn) { old=nw; } else { mask[c]^=1; } temp*=0.95; } } cout << "impossible\n"; }
#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...