Submission #950228

# Submission time Handle Problem Language Result Execution time Memory
950228 2024-03-20T07:04:14 Z Abito Cookies (JOI23_cookies) C++17
0 / 100
1000 ms 27952 KB
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define ppb pop_back
#define ep insert
#define endl '\n'
#define elif else if
#define pow pwr
#define sqrt sqrtt
#define int long long
#define ll long long
typedef unsigned long long ull;
using namespace std;
const int N=20,M=1e6;
int n,b[N],m,dp[M],k,best[M];
bool sz[N];
vector<int> a,h[M];
vector<vector<int>> ans;
map<vector<int>,int> mp;
bool vis[M];
int rec(int hsh){
    //cout<<hsh<<endl;
    mp[h[hsh]]=hsh;
    bool z=1;
    for (auto u:h[hsh]) z&=(!u);
    if (z) return 0;
    if (vis[hsh]) return dp[hsh];
    dp[hsh]=1e6;vis[hsh]=1;
    for (int i=1;i<(1<<n);i++){
        if (!sz[__builtin_popcount(i)]) continue;
        bool go=1;
        for (int j=0;j<n;j++) if ((i&(1<<j)) && h[hsh][j]<=0) {go=0;break;}
        if (!go) continue;
        vector<int> c(n);
        for (int j=0;j<n;j++) if (i&(1<<j)) c[j]=h[hsh][j]-1; else c[j]=h[hsh][j];
        int to=0;
        if (!mp[c]) to=++k,swap(c,h[to]);
        else to=mp[c];
        int x=rec(to)+1;
        if (x<dp[hsh]) dp[hsh]=x,best[hsh]=to;
    }
    return dp[hsh];
}
void getans(int hsh){
    bool z=1;
    for (auto u:h[hsh]) z&=(!u);
    if (z) return;
    vector<int> d;
    for (int i=0;i<n;i++) if (h[best[hsh]][i]<h[hsh][i]) d.pb(i);
    ans.pb(d);
    getans(best[hsh]);
    return;
}
int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    cin>>n;a.resize(n);
    for (int i=0;i<n;i++) cin>>a[i];
    cin>>m;
    for (int j=0;j<m;j++) cin>>b[j],sz[b[j]]=1;
    h[++k]=a;
    int x=rec(1);
    if (x>=1e6){
        cout<<-1<<endl;
        return 0;
    }cout<<x<<endl;
    getans(1);
    for (auto v:ans){
        cout<<v.size()<<' ';
        for (auto u:v) cout<<u+1<<' ';cout<<endl;
    }
    return 0;
}

Compilation message

cookies.cpp: In function 'int32_t main()':
cookies.cpp:70:9: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   70 |         for (auto u:v) cout<<u+1<<' ';cout<<endl;
      |         ^~~
cookies.cpp:70:39: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   70 |         for (auto u:v) cout<<u+1<<' ';cout<<endl;
      |                                       ^~~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 24920 KB Output is correct
2 Correct 8 ms 24920 KB Output is correct
3 Correct 6 ms 24920 KB Output is correct
4 Correct 5 ms 24920 KB Output is correct
5 Correct 5 ms 24924 KB Output is correct
6 Correct 6 ms 24924 KB Output is correct
7 Correct 8 ms 25104 KB Output is correct
8 Execution timed out 1034 ms 27636 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 24924 KB Output is correct
2 Correct 6 ms 24924 KB Output is correct
3 Correct 6 ms 24924 KB Output is correct
4 Correct 5 ms 24924 KB Output is correct
5 Execution timed out 1070 ms 27808 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 24928 KB Output is correct
2 Correct 6 ms 24924 KB Output is correct
3 Correct 8 ms 25092 KB Output is correct
4 Correct 7 ms 24920 KB Output is correct
5 Correct 7 ms 24924 KB Output is correct
6 Correct 6 ms 24924 KB Output is correct
7 Correct 6 ms 25092 KB Output is correct
8 Correct 10 ms 24924 KB Output is correct
9 Correct 6 ms 24920 KB Output is correct
10 Correct 6 ms 24920 KB Output is correct
11 Correct 6 ms 24924 KB Output is correct
12 Correct 7 ms 24924 KB Output is correct
13 Correct 7 ms 24924 KB Output is correct
14 Correct 6 ms 24924 KB Output is correct
15 Correct 7 ms 25036 KB Output is correct
16 Correct 6 ms 24924 KB Output is correct
17 Correct 8 ms 25176 KB Output is correct
18 Correct 6 ms 24920 KB Output is correct
19 Correct 7 ms 24924 KB Output is correct
20 Correct 7 ms 25088 KB Output is correct
21 Correct 7 ms 24920 KB Output is correct
22 Correct 6 ms 24928 KB Output is correct
23 Correct 6 ms 24924 KB Output is correct
24 Correct 10 ms 25260 KB Output is correct
25 Correct 11 ms 25176 KB Output is correct
26 Correct 10 ms 25180 KB Output is correct
27 Correct 11 ms 25180 KB Output is correct
28 Correct 8 ms 25012 KB Output is correct
29 Correct 18 ms 25436 KB Output is correct
30 Correct 13 ms 25424 KB Output is correct
31 Correct 103 ms 26100 KB Output is correct
32 Correct 9 ms 25084 KB Output is correct
33 Correct 17 ms 25688 KB Output is correct
34 Correct 42 ms 25576 KB Output is correct
35 Execution timed out 1062 ms 27952 KB Time limit exceeded
36 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 24920 KB Output is correct
2 Correct 8 ms 24920 KB Output is correct
3 Correct 6 ms 24920 KB Output is correct
4 Correct 5 ms 24920 KB Output is correct
5 Correct 5 ms 24924 KB Output is correct
6 Correct 6 ms 24924 KB Output is correct
7 Correct 8 ms 25104 KB Output is correct
8 Execution timed out 1034 ms 27636 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 24920 KB Output is correct
2 Correct 8 ms 24920 KB Output is correct
3 Correct 6 ms 24920 KB Output is correct
4 Correct 5 ms 24920 KB Output is correct
5 Correct 5 ms 24924 KB Output is correct
6 Correct 6 ms 24924 KB Output is correct
7 Correct 8 ms 25104 KB Output is correct
8 Execution timed out 1034 ms 27636 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 24920 KB Output is correct
2 Correct 8 ms 24920 KB Output is correct
3 Correct 6 ms 24920 KB Output is correct
4 Correct 5 ms 24920 KB Output is correct
5 Correct 5 ms 24924 KB Output is correct
6 Correct 6 ms 24924 KB Output is correct
7 Correct 8 ms 25104 KB Output is correct
8 Execution timed out 1034 ms 27636 KB Time limit exceeded
9 Halted 0 ms 0 KB -