QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#185641 | #6561. Fail Fast | fryan | WA | 0ms | 3764kb | C++14 | 3.7kb | 2023-09-22 13:42:48 | 2023-09-22 13:42:48 |
Judging History
answer
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cfenv>
#include <cfloat>
#include <chrono>
#include <cinttypes>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdarg>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <immintrin.h>
#include <initializer_list>
#include <iomanip>
#include <ios>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <streambuf>
#include <string>
#include <tuple>
#include <type_traits>
#include <variant>
using namespace std;
//numbers
using ll=long long;
#define int ll
using ld=long double;
//pairs
#define P pair
#define pi P<int,int>
#define f first
#define s second
#define mp make_pair
//std data structure
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()
//vectors
#define V vector
#define vi V<int>
#define v2i V<vi>
#define v3i V<v2i>
#define vpi V<pi>
#define vsi V<si>
#define vb V<bool>
#define pb push_back
//sets
#define S set
#define MS multiset
#define US unordered_set
#define si S<int>
#define msi MS<int>
#define usi US<int>
#define ins insert
#define era erase
//maps
#define M map
#define UM unordered_map
#define mii M<int,int>
#define mivi UM<int,vi>
#define misi UM<int,si>
#define umii UM<int,int>
#define umivi UM<int,vi>
#define umisi UM<int,si>
//queues
#define Q queue
#define PQ priority_queue
#define qi Q<int>
#define qpi Q<pi>
#define pqi PQ<int>
#define rpqi PQ<int,vi,greater<int> >
#define pqpi PQ<pi>
#define rpqpi PQ<pi,vpi,greater<pi> >
#define pp P<ld, P< P<ld,ld>, pi > >
//constants
const int MOD=998244353;
const int INF=922337203685477580;
//nt functions
int binpow(int a, int b, int m=MOD) {
a%=m; int res=1;
while (b>0) {
if (b&1) res=res*a%m;
a=a*a%m;
b>>=1;
}
return res;
}
int gcd (int a, int b) {
return b?gcd (b,a%b):a;
}
int lcm (int a, int b) {
return a/gcd(a,b)*b;
}
int inv(int i, int m=MOD) {
return binpow(i, m-2, m);
}
struct DSU {
vector<int> e;
DSU(int N) { e = vector<int>(N, -1); }
int get(int x) { return e[x] < 0 ? x : e[x] = get(e[x]); }
bool same_set(int a, int b) { return get(a) == get(b); }
int size(int x) { return -e[get(x)]; }
bool unite(int x, int y) {x = get(x), y = get(y);if (x == y) return false;if (e[x] > e[y]) swap(x, y);e[x] += e[y]; e[y] = x;return true;}
};
struct ccpp {
bool operator() (pp o1, pp o2) {
return true;
}
};
ld calc(P<ld,ld> x) {
ld ret=x.f/((ld)1-x.s); return ret;
}
signed main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int n; cin>>n;
V<pp> ts(n+1);
for (int i=1; i<=n; i++) {
cin>>ts[i].s.f.f>>ts[i].s.f.s>>ts[i].s.s.f;
ts[i].s.s.s=i; ts[i].f=calc(ts[i].s.f);
}
vi bk(n+1,0);
vi bk2(n+1,0);
vb vis(n+1,0);
DSU dsu(n+1);
S<pp> ord;
for (int i=1; i<=n; i++) {
ord.ins(ts[i]);
bk[i]=i; bk2[i]=i;
}
while (!ord.empty()) {
pp t=*(ord.begin()); ord.erase(ord.begin());
int c=t.s.f.f; int p=t.s.f.s;
int d=t.s.s.f; int i=t.s.s.s;
if (d==0 || vis[d]) {
int cp=i;
while (!vis[cp]) {
vis[cp]=1;
cout<<cp<<"\n";
cp=bk[cp];
}
continue;
}
bk[bk2[dsu.get(d)]]=i;
bk2[dsu.get(d)]=bk2[dsu.get(i)];
dsu.unite(i,d);
pp nd=ts[d];
ord.era(ts[d]);
nd.s.f.f=nd.s.f.f+nd.s.f.s*c;
nd.s.f.s=nd.s.f.s*p;
nd.f=calc(nd.s.f);
ts[d]=nd;
ord.ins(nd);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3724kb
input:
4 100 0.5 0 200 0.1 1 10 0.5 2 10 0.9 0
output:
4 1 2 3
result:
ok correct
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3764kb
input:
4 84 0.716 0 91 0.115 0 19 0.640 1 103 0.455 0
output:
1 3 2 4
result:
wrong answer your plan is not optimal