QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#140812 | #5160. Kebab Pizza | Gamal74# | WA | 1ms | 3596kb | C++20 | 3.6kb | 2023-08-16 20:48:20 | 2023-08-16 20:48:22 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define pp push_back
#define endl '\n'
#define all(x) x.begin(),x.end()
#define ld long double
#define PI acos(-1)
#define sin(a) sin((a)*PI/180)
#define cos(a) cos((a)*PI/180)
#define ones(x) __builtin_popcountll(x)
//#define int ll
using namespace std;
void Drakon() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
#ifdef Clion
freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
#endif
}
unsigned long long inf = 1e10;
const double EPS = 1e-6;
const int MOD = 1000000007, N = 200005, LOG = 25;
ll gcd(ll x, ll y) {
return y ? gcd(y, x % y) : x;
}
ll lcm(ll a, ll b) {
return (a * b) / __gcd(a, b);
}
ll mul(const ll &a, const ll &b) {
return (a % MOD + MOD) * (b % MOD + MOD) % MOD;
}
ll add(const ll &a, const ll &b) {
return (a + b + 2 * MOD) % MOD;
}
ll pw(ll x, ll y) {
ll ret = 1;
while (y > 0) {
if (y % 2 == 0) {
x = mul(x, x);
y = y / 2;
} else {
ret = mul(ret, x);
y = y - 1;
}
}
return ret;
}
void solve() {
int n, k;
cin >> n >> k;
map<int, int>freq;
map<int, multiset<int>>mp;
set<int>alive;
for (int i = 0; i < n; ++i) {
int a, b;
cin >> a >> b;
alive.insert(a);
alive.insert(b);
if(a == b){
freq[a] ++;
mp[a].insert(b);
}
else{
freq[a] ++;
freq[b] ++;
mp[a].insert(b);
mp[b].insert(a);
}
}
int f = -1, s = -1;
while (!alive.empty()){
if(~f){
bool ok = (f == s);
alive.erase(f);
multiset<int>ms = mp[f];
vector<int>vec;
for(auto x : ms){
if(!alive.count(x))continue;
vec.push_back(x);
}
map<int, int>cur;
vector<int>rem;
for(auto x : vec){
if(rem.empty() || rem.back() != x)rem.pp(x);
cur[x] ++;
if(cur[x] == freq[x])rem.pop_back(), alive.erase(x);
}
if(rem.size() > 1){
cout << "impossible";
return;
}
else if(rem.size() == 1){
f = rem.back();
}
else{
f = -1;
swap(f, s);
}
if(ok)break;
}
else{
int z = *alive.begin();
alive.erase(z);
multiset<int>ms = mp[z];
vector<int>vec;
for(auto x : ms){
if(!alive.count(x))continue;
vec.push_back(x);
}
map<int, int>cur;
vector<int>rem;
for(auto x : vec){
if(rem.empty() || rem.back() != x)rem.pp(x);
cur[x] ++;
if(cur[x] == freq[x])rem.pop_back(), alive.erase(x);
}
if(rem.size() > 2){
cout << "impossible";
return;
}
else if(rem.size() == 2){
f = rem[0];
s = rem[1];
}
else if(rem.size() == 1){
f = rem[0];
}
}
}
if(alive.size()){
cout << "impossible";
return;
}
cout << "possible";
}
signed main() {
Drakon();
int t = 1;
//cin >> t;
while (t--) {
solve();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3528kb
input:
7 6 2 2 3 6 1 1 1 5 4 5 6 6 6 5
output:
possible
result:
ok single line: 'possible'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3460kb
input:
5 5 1 3 1 5 2 3 2 5 3 4
output:
possible
result:
ok single line: 'possible'
Test #3:
score: 0
Accepted
time: 1ms
memory: 3488kb
input:
6 7 1 2 2 3 3 4 4 5 3 6 6 7
output:
impossible
result:
ok single line: 'impossible'
Test #4:
score: 0
Accepted
time: 1ms
memory: 3592kb
input:
8 4 1 1 1 2 2 1 2 2 3 3 3 4 4 3 4 4
output:
possible
result:
ok single line: 'possible'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3524kb
input:
4 4 1 2 2 1 3 4 4 3
output:
possible
result:
ok single line: 'possible'
Test #6:
score: 0
Accepted
time: 1ms
memory: 3596kb
input:
5 4 1 1 1 4 2 2 2 4 3 4
output:
possible
result:
ok single line: 'possible'
Test #7:
score: 0
Accepted
time: 1ms
memory: 3532kb
input:
6 4 1 1 1 4 2 2 2 4 3 3 3 4
output:
impossible
result:
ok single line: 'impossible'
Test #8:
score: -100
Wrong Answer
time: 1ms
memory: 3552kb
input:
4 5 1 2 3 4 4 5 5 3
output:
possible
result:
wrong answer 1st lines differ - expected: 'impossible', found: 'possible'