QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#473004 | #8873. Keys | PetroTarnavskyi | Compile Error | / | / | C++23 | 3.7kb | 2024-07-11 20:52:37 | 2024-07-11 20:52:37 |
Judging History
This is the latest submission verdict.
- [2024-07-11 20:52:37]
- Judged
- Verdict: Compile Error
- Time: 0ms
- Memory: 0kb
- [2024-07-11 20:52:37]
- Submitted
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 = 100'447;
VI g[N];
bool used[N];
int from[N];
int p[N];
map<PII, int> mp;
void dfs1(int v)
{
used[v] = true;
for (auto to : g[v])
{
if (!used[to])
{
from[to] = v;
dfs1(to);
}
}
}
int dfs2(int v, int par = -1)
{
used[v] = 1;
p[v] = par;
for (auto to : g[v])
{
if (to == par)
continue;
if (to == 1)
return v;
if(used[to])
continue;
int res = dfs2(to, v);
if (res != -1)
return res;
}
return -1;
}
void printKeys(const VI& v)
{
FOR (i, 0, SZ(v))
{
if (i)
cout << ' ';
cout << v[i];
}
cout << '\n';
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
FOR (i, 0, m)
{
int a, b;
cin >> a >> b;
mp[{a, b}] = i;
mp[{b, a}] = i;
g[a].PB(b);
g[b].PB(a);
}
used[1] = true;
dfs1(0);
int cnt = 0;
for (auto to : g[1])
{
if (used[to])
cnt++;
}
if (cnt >= 2)
{
int u = -1;
for (auto to : g[1])
{
if (used[to])
u = to;
}
int U = u;
VI path = {1, u};
while (u != 0)
{
u = from[u];
path.PB(u);
}
set<int> marichka;
FOR (i, 0, SZ(path) - 1)
marichka.insert(mp[{path[i], path[i + 1]}]);
VI zenyk;
FOR (i, 0, m)
if (!marichka.count(i))
zenyk.PB(i);
reverse(ALL(path));
VI mar(ALL(marichka));
printKeys(mar);
printKeys(zenyk);
FOR (i, 1, SZ(path))
{
cout << "MOVE " << path[i] << '\n';
if (i + 1 != SZ(path))
cout << "DROP " << mp[{path[i - 1], path[i]}] << '\n';
}
cout << "DONE\n";
path.clear();
int v = -1;
for (auto to : g[1])
{
if (used[to] && to != U)
v = to;
}
path = {1, v};
while (v != 0)
{
v = from[v];
path.PB(v);
}
FOR (i, 0, SZ(path) - 1)
{
cout << "GRAB\n";
cout << "MOVE " << path[i + 1] << '\n';
}
cout << "DONE\n";
}
else
{
if (cnt == 0)
{
cout << "No solution\n";
return 0;
}
int u = -1;
for (auto to : g[1])
{
if (used[to])
u = to;
}
VI path = {1, u};
while (u != 0)
{
u = from[u];
path.PB(u);
}
reverse(ALL(path));
FOR(i, 0, n)
used[i] = false;
int v = dfs2(1);
if (v == -1)
{
cout << "No solution\n";
return 0;
}
int V = v;
VI cycle = { 1, v };
while (v != 1)
{
v = p[v];
cycle.PB(v);
}
reverse(ALL(cycle));
set<int> marichka;
FOR (i, 0, SZ(path) - 1)
marichka.insert(mp[{path[i], path[i + 1]}]);
marichka.insert(mp[{1, V}]);
VI zenyk;
FOR (i, 0, m)
if (!marichka.count(i))
zenyk.PB(i);
VI mar(ALL(marichka));
printKeys(mar);
printKeys(zenyk);
FOR (i, 1, SZ(path))
{
cout << "MOVE " << path[i] << '\n';
if (i + 1 != SZ(path))
cout << "DROP " << mp[{path[i - 1], path[i]}] << '\n';
}
cout << "MOVE " << V << '\n';
cout << "DROP " << mp[{1, U}] << '\n';
cout << "MOVE " << 1 << '\n';
cout << "DONE\n";
FOR (i, 1, SZ(cycle) - 1)
{
cout << "MOVE " << cycle[i] << '\n';
}
cout << "GRAB\n";
RFOR (i, SZ(cycle) - 2, 0)
cout << "MOVE " << cycle[i] << '\n';
RFOR (i, SZ(path) - 1, 0)
{
cout << "GRAB\n";
cout << "MOVE " << path[i] << '\n';
}
cout << "DONE\n";
}
return 0;
}
详细
answer.code: In function ‘int main()’: answer.code:214:43: error: ‘U’ was not declared in this scope 214 | cout << "DROP " << mp[{1, U}] << '\n'; | ^ answer.code:214:38: error: no match for ‘operator[]’ (operand types are ‘std::map<std::pair<int, int>, int>’ and ‘<brace-enclosed initializer list>’) 214 | cout << "DROP " << mp[{1, U}] << '\n'; | ^ In file included from /usr/include/c++/13/map:63, from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:152, from answer.code:1: /usr/include/c++/13/bits/stl_map.h:504:7: note: candidate: ‘std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const key_type&) [with _Key = std::pair<int, int>; _Tp = int; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<const std::pair<int, int>, int> >; mapped_type = int; key_type = std::pair<int, int>]’ 504 | operator[](const key_type& __k) | ^~~~~~~~ /usr/include/c++/13/bits/stl_map.h:504:34: note: no known conversion for argument 1 from ‘<brace-enclosed initializer list>’ to ‘const std::map<std::pair<int, int>, int>::key_type&’ {aka ‘const std::pair<int, int>&’} 504 | operator[](const key_type& __k) | ~~~~~~~~~~~~~~~~^~~ /usr/include/c++/13/bits/stl_map.h:524:7: note: candidate: ‘std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](key_type&&) [with _Key = std::pair<int, int>; _Tp = int; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<const std::pair<int, int>, int> >; mapped_type = int; key_type = std::pair<int, int>]’ 524 | operator[](key_type&& __k) | ^~~~~~~~ /usr/include/c++/13/bits/stl_map.h:524:29: note: no known conversion for argument 1 from ‘<brace-enclosed initializer list>’ to ‘std::map<std::pair<int, int>, int>::key_type&&’ {aka ‘std::pair<int, int>&&’} 524 | operator[](key_type&& __k) | ~~~~~~~~~~~^~~