QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#185609 | #6561. Fail Fast | fryan | WA | 0ms | 3952kb | C++14 | 3.5kb | 2023-09-22 13:04:27 | 2023-09-22 13:04:28 |
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 ff first
#define ss 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> >
//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 t {
int c;
ld p;
int d;
int i;
};
struct cct {
bool operator() (t t1, t t2) {
ld x1=t1.c*(1-t2.p);
ld x2=t2.c*(1-t1.p);
return (x1>x2);
}
};
signed main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int n; cin>>n;
V<t> ts(n+1);
for (int i=1; i<=n; i++) {
cin>>ts[i].c>>ts[i].p>>ts[i].d; ts[i].i=i;
}
vi fir;
vi las;
vi bk(n+1,0);
vi bk2(n+1,0);
vb vis(n+1,0);
vis[0]=1;
DSU dsu(n+1);
PQ<t,V<t>,cct> ord;
for (int i=1; i<=n; i++) {
ord.push(ts[i]);
bk[i]=i; bk2[i]=i;
}
while (!ord.empty()) {
t k=ord.top(); ord.pop();
if (k.d==0 || vis[k.d]) {
int cp=k.i;
while (!vis[cp]) {
vis[cp]=1;
cout<<cp<<"\n";
cp=bk[cp];
}
continue;
}
bk[bk2[dsu.get(k.d)]]=k.i;
bk2[dsu.get(k.d)]=bk2[dsu.get(k.i)];
dsu.unite(k.d,k.i);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3952kb
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: 3724kb
input:
4 84 0.716 0 91 0.115 0 19 0.640 1 103 0.455 0
output:
2 4 1 3
result:
wrong answer your plan is not optimal