QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#521676#2193. Cactus RevengesocpiteWA 1ms3868kbC++232.1kb2024-08-16 13:52:352024-08-16 13:52:36

Judging History

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

  • [2024-08-16 13:52:36]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3868kb
  • [2024-08-16 13:52:35]
  • 提交

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: 100
Accepted
time: 0ms
memory: 3568kb

input:

5
2 2 3 2 1

output:

5
2 3 5
2 1 2
2 2 3
2 3 4
2 4 1

result:

ok ok, n = 5

Test #2:

score: 0
Accepted
time: 0ms
memory: 3636kb

input:

4
3 3 2 2

output:

-1

result:

ok ok, n = 4

Test #3:

score: 0
Accepted
time: 0ms
memory: 3568kb

input:

6
1 2 1 1 2 1

output:

-1

result:

ok ok, n = 6

Test #4:

score: 0
Accepted
time: 0ms
memory: 3516kb

input:

15
1 4 3 2 2 2 2 2 4 4 2 2 2 2 2

output:

18
2 3 1
2 4 3
2 4 2
2 3 2
2 5 2
2 5 9
2 2 9
2 7 6
2 7 10
2 6 10
2 8 9
2 9 10
2 10 11
2 11 12
2 12 13
2 13 14
2 14 15
2 15 8

result:

ok ok, n = 15

Test #5:

score: 0
Accepted
time: 0ms
memory: 3628kb

input:

2
1 1

output:

1
2 1 2

result:

ok ok, n = 2

Test #6:

score: 0
Accepted
time: 0ms
memory: 3572kb

input:

3
1 1 1

output:

-1

result:

ok ok, n = 3

Test #7:

score: 0
Accepted
time: 0ms
memory: 3632kb

input:

3
1 1 2

output:

2
2 3 1
2 2 3

result:

ok ok, n = 3

Test #8:

score: 0
Accepted
time: 0ms
memory: 3564kb

input:

3
1 2 2

output:

-1

result:

ok ok, n = 3

Test #9:

score: 0
Accepted
time: 0ms
memory: 3624kb

input:

3
2 2 2

output:

3
2 1 2
2 2 3
2 3 1

result:

ok ok, n = 3

Test #10:

score: 0
Accepted
time: 0ms
memory: 3628kb

input:

4
2 1 2 1

output:

3
2 1 2
2 3 1
2 3 4

result:

ok ok, n = 4

Test #11:

score: 0
Accepted
time: 0ms
memory: 3808kb

input:

4
1 1 1 3

output:

3
2 4 1
2 4 2
2 3 4

result:

ok ok, n = 4

Test #12:

score: 0
Accepted
time: 0ms
memory: 3628kb

input:

4
2 1 2 3

output:

4
2 4 2
2 1 3
2 3 4
2 4 1

result:

ok ok, n = 4

Test #13:

score: 0
Accepted
time: 0ms
memory: 3796kb

input:

4
2 2 2 2

output:

4
2 1 2
2 2 3
2 3 4
2 4 1

result:

ok ok, n = 4

Test #14:

score: 0
Accepted
time: 0ms
memory: 3864kb

input:

5
4 2 2 2 2

output:

6
2 3 2
2 3 1
2 2 1
2 1 4
2 4 5
2 5 1

result:

ok ok, n = 5

Test #15:

score: 0
Accepted
time: 0ms
memory: 3600kb

input:

6
2 1 2 3 2 4

output:

7
2 4 2
2 3 1
2 3 6
2 1 6
2 4 5
2 5 6
2 6 4

result:

ok ok, n = 6

Test #16:

score: 0
Accepted
time: 1ms
memory: 3600kb

input:

10
5 2 2 2 2 5 2 2 2 2

output:

13
2 3 2
2 3 1
2 2 1
2 5 4
2 5 6
2 4 6
2 8 7
2 8 1
2 7 1
2 6 1
2 6 9
2 9 10
2 10 6

result:

ok ok, n = 10

Test #17:

score: 0
Accepted
time: 0ms
memory: 3628kb

input:

6
2 5 2 2 1 2

output:

7
2 2 5
2 3 1
2 3 2
2 1 2
2 2 4
2 4 6
2 6 2

result:

ok ok, n = 6

Test #18:

score: 0
Accepted
time: 0ms
memory: 3860kb

input:

8
3 3 4 1 2 1 2 2

output:

9
2 1 4
2 2 6
2 2 1
2 2 3
2 1 3
2 3 5
2 5 7
2 7 8
2 8 3

result:

ok ok, n = 8

Test #19:

score: 0
Accepted
time: 0ms
memory: 3564kb

input:

8
3 2 4 2 2 3 2 2

output:

10
2 4 2
2 4 3
2 2 3
2 5 3
2 5 1
2 3 1
2 6 1
2 6 7
2 7 8
2 8 6

result:

ok ok, n = 8

Test #20:

score: 0
Accepted
time: 0ms
memory: 3636kb

input:

20
2 2 1 1 4 2 2 7 1 4 2 1 4 2 2 2 4 3 6 2

output:

-1

result:

ok ok, n = 20

Test #21:

score: 0
Accepted
time: 0ms
memory: 3572kb

input:

20
2 2 2 2 3 2 1 3 2 2 1 2 2 3 4 2 5 6 4 4

output:

27
2 5 7
2 8 11
2 2 1
2 2 15
2 1 15
2 4 3
2 4 19
2 3 19
2 6 5
2 6 20
2 5 20
2 9 8
2 9 17
2 8 17
2 12 10
2 12 18
2 10 18
2 15 13
2 15 18
2 13 18
2 18 16
2 18 14
2 16 14
2 17 14
2 17 19
2 19 20
2 20 17

result:

ok ok, n = 20

Test #22:

score: 0
Accepted
time: 0ms
memory: 3560kb

input:

4
1 1 1 1

output:

-1

result:

ok ok, n = 4

Test #23:

score: 0
Accepted
time: 0ms
memory: 3572kb

input:

4
2 1 1 1

output:

-1

result:

ok ok, n = 4

Test #24:

score: 0
Accepted
time: 0ms
memory: 3620kb

input:

4
2 1 1 2

output:

3
2 1 2
2 4 1
2 3 4

result:

ok ok, n = 4

Test #25:

score: 0
Accepted
time: 0ms
memory: 3624kb

input:

4
1 3 1 2

output:

-1

result:

ok ok, n = 4

Test #26:

score: 0
Accepted
time: 0ms
memory: 3564kb

input:

4
3 1 3 1

output:

-1

result:

ok ok, n = 4

Test #27:

score: 0
Accepted
time: 0ms
memory: 3624kb

input:

4
2 2 1 2

output:

-1

result:

ok ok, n = 4

Test #28:

score: 0
Accepted
time: 0ms
memory: 3572kb

input:

4
1 2 2 3

output:

4
2 4 1
2 2 3
2 3 4
2 4 2

result:

ok ok, n = 4

Test #29:

score: 0
Accepted
time: 0ms
memory: 3632kb

input:

4
3 2 3 1

output:

-1

result:

ok ok, n = 4

Test #30:

score: 0
Accepted
time: 0ms
memory: 3604kb

input:

4
3 1 3 3

output:

-1

result:

ok ok, n = 4

Test #31:

score: 0
Accepted
time: 0ms
memory: 3604kb

input:

4
2 2 2 3

output:

-1

result:

ok ok, n = 4

Test #32:

score: 0
Accepted
time: 0ms
memory: 3628kb

input:

4
3 3 2 3

output:

-1

result:

ok ok, n = 4

Test #33:

score: 0
Accepted
time: 0ms
memory: 3564kb

input:

4
3 3 3 3

output:

-1

result:

ok ok, n = 4

Test #34:

score: 0
Accepted
time: 0ms
memory: 3568kb

input:

20
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

output:

-1

result:

ok ok, n = 20

Test #35:

score: 0
Accepted
time: 0ms
memory: 3600kb

input:

20
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2

output:

20
2 1 2
2 2 3
2 3 4
2 4 5
2 5 6
2 6 7
2 7 8
2 8 9
2 9 10
2 10 11
2 11 12
2 12 13
2 13 14
2 14 15
2 15 16
2 16 17
2 17 18
2 18 19
2 19 20
2 20 1

result:

ok ok, n = 20

Test #36:

score: 0
Accepted
time: 0ms
memory: 3636kb

input:

20
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3

output:

-1

result:

ok ok, n = 20

Test #37:

score: 0
Accepted
time: 0ms
memory: 3828kb

input:

20
4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4

output:

-1

result:

ok ok, n = 20

Test #38:

score: 0
Accepted
time: 0ms
memory: 3620kb

input:

20
9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9

output:

-1

result:

ok ok, n = 20

Test #39:

score: 0
Accepted
time: 0ms
memory: 3868kb

input:

20
10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10

output:

-1

result:

ok ok, n = 20

Test #40:

score: 0
Accepted
time: 0ms
memory: 3520kb

input:

20
18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18

output:

-1

result:

ok ok, n = 20

Test #41:

score: 0
Accepted
time: 0ms
memory: 3632kb

input:

20
19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19

output:

-1

result:

ok ok, n = 20

Test #42:

score: 0
Accepted
time: 0ms
memory: 3628kb

input:

20
2 2 2 1 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2

output:

19
2 1 4
2 2 1
2 3 2
2 5 3
2 6 5
2 7 6
2 8 7
2 9 8
2 10 9
2 12 10
2 13 11
2 14 12
2 15 13
2 16 14
2 17 15
2 18 16
2 19 17
2 20 18
2 19 20

result:

ok ok, n = 20

Test #43:

score: 0
Accepted
time: 0ms
memory: 3560kb

input:

20
1 1 1 1 1 19 1 1 1 1 1 1 1 1 1 1 1 1 1 1

output:

19
2 6 1
2 6 2
2 6 3
2 6 4
2 6 5
2 6 7
2 6 8
2 6 9
2 6 10
2 6 11
2 6 12
2 6 13
2 6 14
2 6 15
2 6 16
2 6 17
2 6 18
2 6 19
2 6 20

result:

ok ok, n = 20

Test #44:

score: 0
Accepted
time: 0ms
memory: 3632kb

input:

20
2 1 4 1 3 2 1 2 2 5 1 1 1 1 1 1 2 1 3 1

output:

-1

result:

ok ok, n = 20

Test #45:

score: 0
Accepted
time: 0ms
memory: 3572kb

input:

20
1 2 2 2 2 1 3 1 1 3 1 2 3 1 3 2 1 3 3 1

output:

19
2 7 1
2 10 6
2 13 8
2 15 9
2 18 11
2 19 14
2 2 17
2 3 2
2 4 3
2 5 4
2 7 5
2 10 7
2 12 10
2 13 12
2 15 13
2 16 15
2 18 16
2 19 18
2 19 20

result:

ok ok, n = 20

Test #46:

score: -100
Wrong Answer
time: 0ms
memory: 3832kb

input:

20
1 5 1 5 1 1 2 1 2 1 2 2 1 2 4 2 2 3 1 1

output:

-1

result:

wrong answer no solution found but it exists