Submission #494755

# Submission time Handle Problem Language Result Execution time Memory
494755 2021-12-16T05:47:03 Z dannyboy20031204 DEL13 (info1cup18_del13) C++17
40 / 100
8 ms 2048 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, inf = 1e9 + 1;
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;
    bool dp[n + 1][2]{};
    int par[n + 1][2]{}, last[n + 1]{};
    dp[0][0] = 1;
    for (int i = 1; i <= n; i++){
        if (stay[i]){
            dp[i][0] |= dp[i - 1][0];
            par[i][0] = i - 1;
            last[i] = i;
            continue;
        }
        last[i] = last[i - 1];
        if (i >= 3 and !stay[i - 1] and !stay[i - 2] and dp[i - 2][0]){
            par[i][0] = i - 2;
            dp[i][0] = 1;
        }
        if (i >= 2 and !stay[i - 1] and (dp[i - 2][1] or dp[i - 2][0])){
            par[i][0] = i - 2;
            dp[i][1] = 1;
        }
        if (last[i] and i - last[i] <= last[i] - last[last[i] - 1] - 1){
            int p = i - (i - last[i]) * 2 - 1;
            assert(p >= 0);
            if (dp[p][0] or dp[p][1]) {
                dp[i][0] = 1;
                par[i][0] = p;
            }
        }
        //db(i, dp[i][0], dp[i][1]);
    }
    if (!dp[n][0]) return void(cout << -1 << '\n');
    deque<int> ans;
    for (int i = n; i; i){
        if (dp[i][0]){
            if (par[i][0] == i - 2){
                ans.push_front(i - 1);
            }
            else{
                int mid = (i + par[i][0] + 1) / 2;
                for (int j = 0; j < i - mid; j++) ans.push_back(mid);
            }
            i = par[i][0];
        }
        else{
            ans.push_front(i);
            i = par[i][1];
        }
    }
    cout << ans.size() << '\n';
    for (int i : ans) cout << i << ' ';
    cout << '\n';
}
signed main(){
    file;
    int t;
    cin >> t;
    while (t--)
        solve();
}

Compilation message

del13.cpp: In function 'void solve()':
del13.cpp:54:24: warning: for increment expression has no effect [-Wunused-value]
   54 |     for (int i = n; i; i){
      |                        ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is partially correct
2 Correct 1 ms 204 KB Output is partially correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is partially correct
2 Correct 1 ms 204 KB Output is partially correct
3 Correct 3 ms 332 KB Output is partially correct
4 Correct 3 ms 332 KB Output is partially correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 464 KB Output is partially correct
2 Correct 2 ms 1484 KB Output is partially correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is partially correct
2 Correct 1 ms 204 KB Output is partially correct
3 Correct 3 ms 332 KB Output is partially correct
4 Correct 3 ms 332 KB Output is partially correct
5 Correct 1 ms 204 KB Output is partially correct
6 Correct 1 ms 204 KB Output is partially correct
7 Correct 1 ms 204 KB Output is partially correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is partially correct
2 Correct 1 ms 204 KB Output is partially correct
3 Correct 3 ms 332 KB Output is partially correct
4 Correct 3 ms 332 KB Output is partially correct
5 Correct 1 ms 204 KB Output is partially correct
6 Correct 1 ms 204 KB Output is partially correct
7 Correct 1 ms 204 KB Output is partially correct
8 Correct 5 ms 1612 KB Output is partially correct
9 Correct 5 ms 1612 KB Output is partially correct
10 Correct 6 ms 1612 KB Output is partially correct
11 Correct 8 ms 2048 KB Output is partially correct