QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#346622 | #4770. Binomial coefficients | PetroTarnavskyi# | WA | 0ms | 3592kb | C++20 | 2.5kb | 2024-03-08 19:34:10 | 2024-03-08 19:34:10 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;
const int N = 104;
const db vel = 340;
const int INF = 1e9;
map<string, int> mp;
PII p[N];
string s[N];
vector<pair<int, db>> g[N];
VI g2[N];
int n, m;
bool used[N];
VI tps;
bool shoot[N];
void clear()
{
mp.clear();
tps.clear();
FOR (i, 0, n)
{
g[i].clear();
g2[i].clear();
used[i] = false;
shoot[i] = false;
}
}
db dis(int i, int j)
{
db dx = p[i].F - p[j].F;
db dy = p[i].S - p[j].S;
return sqrt(dx * dx + dy * dy);
}
bool Belmann(int v)
{
vector<db> dis(n, INF);
dis[v] = 0;
bool ok = false;
FOR (i, 0, n)
{
if (!shoot[i])
continue;
ok = false;
FOR (j, 0, n)
{
if (!shoot[j])
continue;
for (auto [to, d] : g[j])
{
if (!shoot[to])
continue;
if (dis[v] + d < dis[to])
{
dis[to] = dis[v] + d;
ok = true;
}
}
}
}
FOR (i, 0, n)
{
if (i == v)
continue;
if (dis[i] < 0)
g2[v].PB(i);
}
return !ok;
}
void dfs(int v)
{
used[v] = true;
for (auto to : g2[v])
if (!used[to])
dfs(to);
if (shoot[v])
tps.PB(v);
}
void solve()
{
cin >> n >> m;
FOR (i, 0, n)
{
cin >> s[i];
mp[s[i]] = i;
cin >> p[i].F >> p[i].S;
}
FOR (i, 0, m)
{
string t;
cin >> t;
int c = mp[t];
cin >> t >> t;
int a = mp[t];
cin >> t >> t >> t;
int b = mp[t];
shoot[a] = true;
shoot[b] = true;
g[a].PB({b, dis(c, b) / vel - dis(c, a) / vel});
}
bool ok = true;
FOR (i, 0, n)
{
if (shoot[i])
ok &= Belmann(i);
if (!ok)
{
cout << "IMPOSSIBLE\n";
clear();
return;
}
}
FOR (i, 0, n)
{
if (!used[i])
dfs(i);
}
reverse(ALL(tps));
bool unique = true;
FOR (i, 0, SZ(tps) - 1)
{
int v = tps[i];
int u = tps[i + 1];
bool is = false;
for (auto to : g2[v])
is |= to == u;
unique &= is;
}
if (unique)
{
FOR (i, 0, SZ(tps))
{
if (i)
cout << ' ';
cout << s[tps[i]];
}
cout << '\n';
clear();
}
else
{
clear();
cout << "UNKNOWN\n";
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--)
{
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3592kb
input:
2 2 15
output:
result:
wrong answer 1st lines differ - expected: '1', found: ''