답안 #494726

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
494726 2021-12-16T03:54:50 Z dannyboy20031204 DEL13 (info1cup18_del13) C++17
15 / 100
59 ms 4416 KB
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define mp make_pair 
using namespace std;
void db() {cout << endl;}
template <typename T, typename ...U> void db(T a, U ...b) {
    //return;
    cout << a << ' ', db(b...);
}
#ifdef Cloud
#define file freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#else
#define file ios::sync_with_stdio(false); cin.tie(0)
#endif
const int N = 3001;
void solve(){
    int n, q;
    cin >> n >> q;
    bool stay[n + 1]{};
    for (int p, i = 0; i < q; i++) cin >> p, stay[p] = 1;
    set<pair<int, int>> s;
    vector<int> ans;
    for (int i = 1; i <= n; i++){
        if (!stay[i] and s.size() >= 2){
            auto u = *(--s.end());
            auto v = *(--(--s.end()));
            if (!u.se and !v.se){
                ans.push_back(u.fi);
                s.erase(u);
                s.erase(v);
            }
        }
        s.insert({i, stay[i]});
    }
    for (auto i : s){
        if (i.se == 0) continue;
        for (int t = 0; t < 2; t++){
            auto it = s.upper_bound(i);
            auto it2 = s.lower_bound(i);
            if (it == s.end() or it2 == s.begin()) continue;
            it2--;
            auto u = *it2, v = *it;
            if (u.se or v.se) continue;
            ans.push_back(i.fi);
            s.erase(u);
            s.erase(v);
        }
    }
    for (auto i : s){
        if (i.se == 0){
            cout << -1 << '\n';
            return;
        }
    }
    cout << ans.size() << '\n';
    for (int i : ans) cout << i << ' ';
    cout << '\n';
}
signed main(){
    file;
    int t;
    cin >> t;
    while (t--)
        solve();
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 332 KB Output isn't correct
2 Incorrect 1 ms 208 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 332 KB Output isn't correct
2 Incorrect 1 ms 208 KB Output isn't correct
3 Incorrect 9 ms 396 KB Output isn't correct
4 Incorrect 9 ms 404 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 464 KB Output is correct
2 Correct 32 ms 868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 332 KB Output isn't correct
2 Incorrect 1 ms 208 KB Output isn't correct
3 Incorrect 9 ms 396 KB Output isn't correct
4 Incorrect 9 ms 404 KB Output isn't correct
5 Incorrect 2 ms 328 KB Output isn't correct
6 Incorrect 2 ms 336 KB Output isn't correct
7 Incorrect 3 ms 208 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 332 KB Output isn't correct
2 Incorrect 1 ms 208 KB Output isn't correct
3 Incorrect 9 ms 396 KB Output isn't correct
4 Incorrect 9 ms 404 KB Output isn't correct
5 Incorrect 2 ms 328 KB Output isn't correct
6 Incorrect 2 ms 336 KB Output isn't correct
7 Incorrect 3 ms 208 KB Output isn't correct
8 Incorrect 38 ms 1000 KB Output isn't correct
9 Incorrect 45 ms 1596 KB Output isn't correct
10 Incorrect 44 ms 2248 KB Output isn't correct
11 Incorrect 59 ms 4416 KB Output isn't correct