# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
950221 | Abito | Cookies (JOI23_cookies) | C++17 | 1050 ms | 145372 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
bool vis[M];
int rec(int hsh){
//cout<<hsh<<endl;
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;
int to=++k;
h[to].resize(n);
for (int j=0;j<n;j++) if (i&(1<<j)) h[to][j]=h[hsh][j]-1; else h[to][j]=h[hsh][j];
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;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |