QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#521675 | #2193. Cactus Revenge | socpite | WA | 0ms | 3824kb | C++23 | 2.1kb | 2024-08-16 13:51:59 | 2024-08-16 13:52:00 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int no(){
cout << "-1";
return 0;
}
int main() {
set<pair<int, int>> st;
int n;
cin >> n;
int sum = 0;
for(int i = 1; i <= n; i++){
int x;
cin >> x;
st.insert({x, i});
}
vector<pair<int, int>> vec;
while(!st.empty()){
auto ele = *st.begin();
st.erase(st.begin());
if(ele.first == 1){
if(st.empty())return no();
auto it = st.lower_bound({3, 0});
while(it != st.end() && it->first&1)it++;
if(it == st.end())it = st.lower_bound({2, 0});
if(it == st.end()){
if(st.size() >= 2)return no();
vec.push_back({ele.second, st.begin()->second});
break;
}
auto nw = *it;
st.erase(it);
nw.first--;
vec.push_back({nw.second, ele.second});
st.insert(nw);
}
else if(ele.first == 2){
if(st.size() < 2 || st.begin()->first != 2)return no();
auto it = st.lower_bound({4, 0});
if(it == st.end())it = st.lower_bound({3, 0});
if(it == st.end()){
if(st.size() < 2)return no();
int prv = ele.second;
for(auto v: st){
vec.push_back({prv, v.second});
prv = v.second;
}
vec.push_back({prv, ele.second});
break;
}
else {
auto nxt = *st.begin();
st.erase(st.begin());
vec.push_back({nxt.second, ele.second});
vec.push_back({nxt.second, it->second});
vec.push_back({ele.second, it->second});
auto nw = *it;
nw.first -= 2;
st.erase(it);
st.insert(nw);
}
}
else return no();
}
cout << vec.size() << "\n";
for(auto v: vec)cout << "2 " << v.first << " " << v.second << "\n";
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3824kb
input:
5 2 2 3 2 1
output:
-1
result:
wrong answer no solution found but it exists