QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#346630#4776. Smoking gunPetroTarnavskyi#AC ✓129ms3912kbC++202.5kb2024-03-08 19:44:552024-03-08 19:44:55

Judging History

你现在查看的是最新测评结果

  • [2024-03-08 19:44:55]
  • 评测
  • 测评结果:AC
  • 用时:129ms
  • 内存:3912kb
  • [2024-03-08 19:44:55]
  • 提交

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)
	{
		ok = false;
		FOR (j, 0, n)
		{
			if (!shoot[j])
				continue;
			for (auto [to, d] : g[j])
			{	
				if (!shoot[to])
					continue;
				if (dis[j] + d < dis[to])
				{
					dis[to] = dis[j] + 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[b].PB({a, 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)
	{
		reverse(ALL(tps));
		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;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3524kb

input:

3
4 2
BillyTheKid 0 0
Andy 10 0
John 19 0
Larry 20 0
Andy heard BillyTheKid firing before John
Larry heard John firing before BillyTheKid
2 2
Andy 0 0
Beate 0 1
Andy heard Beate firing before Andy
Beate heard Andy firing before Beate
3 1
Andy 0 0
Beate 0 1
Charles 1 3
Beate heard Andy firing before ...

output:

BillyTheKid John
IMPOSSIBLE
UNKNOWN

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 129ms
memory: 3912kb

input:

100
3 2
A 9 3
B 9 9
C 0 0
C heard A firing before B
A heard B firing before A
4 3
A 0 0
B 10 0
C 10 1
D 5 1
B heard A firing before B
B heard B firing before C
D heard C firing before A
3 1
A 0 0
B 0 1
C 1000000 0
C heard A firing before B
4 2
A 0 0
B 0 1
C 1000000 0
D 500000 0
C heard A firing befo...

output:

IMPOSSIBLE
IMPOSSIBLE
UNKNOWN
IMPOSSIBLE
B A
UNKNOWN
SHTab SHTac SHTaa
IMPOSSIBLE
ag ah aj ac ab ae aa ad ai
UNKNOWN
ab ai
UNKNOWN
ai ab ad ac ae aa ah
ad ah ai af aa
ab ar ah al ao ac an aa aq af at ae aj ai ap ag am
UNKNOWN
ac ar ak ao aa ag ae aq an ai
IMPOSSIBLE
at as ae ac
ah ai ag am ad an ap ...

result:

ok 100 lines