Submission #825789
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;i<n;i++)
#define ll long long
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%I64d",&x)
#define ss(s) scanf("%s",s)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define clr(x) memset(x, 0, sizeof(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
const int mod = 1000000007;
const int N = 2e5;
vi g[N];
ll a[N] ,cnt[N];
int mpow(int base, int exp);
void ipgraph(int n, int m);
void dfs(int u, int par);
ll n, L;
vector<ll> ans;
bool go(int lo, int hi, ll sum){
if (sum<L)return false;
if (lo+1 == hi){
ans.pb(lo+1);
return true;
}
ll x = a[lo];
ll y = a[hi];
if (x<=y and go(lo+1, hi, sum-x)){
ans.pb(lo+1);
return true;
}
if (x>y and go(lo, hi-1, sum-y)){
ans.pb(hi);
return true;
}
return false;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string no = "Impossible\n";
string yes = "Possible\n";
cin>>n>>L;
int i;
ll sum = 0;
int lo = 0, hi = n-1;
fo(i, n) cin>>a[i], sum += a[i];
if (sum < L){
cout<<no;
return 0;
}
if (go(0, n-1, sum)){
cout<<yes;
// cout<<ans.size()<<endl;
fo(i, ans.size()){
cout<<ans[ans.size()-1-i]<<endl;
}
}
else{
cout<<no;
}
// while(lo+1<=hi){
// ll x, y;
// x = a[lo];
// y = a[hi];
// }
return 0;
}
int mpow(int base, int exp) {
base %= mod;
int result = 1;
while (exp > 0) {
if (exp & 1) result = ((ll)result * base) % mod;
base = ((ll)base * base) % mod;
exp >>= 1;
}
return result;
}
void ipgraph(int n, int m){
int i, u, v;
while(m--){
cin>>u>>v;
g[u-1].pb(v-1);
g[v-1].pb(u-1);
}
}
void dfs(int u, int par){
for(int v:g[u]){
if (v == par) continue;
dfs(v, u);
}
}
Submission Info
Submission Time |
|
Task |
C - Knot Puzzle |
User |
rachitjain |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
2174 Byte |
Status |
WA |
Exec Time |
763 ms |
Memory |
13428 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
0 / 500 |
Status |
|
|
Set Name |
Test Cases |
Sample |
0_00.txt, 0_01.txt, 0_02.txt |
All |
0_00.txt, 0_01.txt, 0_02.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt, 1_18.txt, 1_19.txt, 1_20.txt, 1_21.txt, 1_22.txt, 1_23.txt, 1_24.txt, 1_25.txt, 1_26.txt, 1_27.txt, 1_28.txt, 1_29.txt, 1_30.txt, 1_31.txt |
Case Name |
Status |
Exec Time |
Memory |
0_00.txt |
AC |
11 ms |
4992 KB |
0_01.txt |
AC |
10 ms |
4992 KB |
0_02.txt |
AC |
10 ms |
4992 KB |
1_00.txt |
AC |
11 ms |
4992 KB |
1_01.txt |
AC |
10 ms |
4992 KB |
1_02.txt |
AC |
619 ms |
13428 KB |
1_03.txt |
AC |
33 ms |
12032 KB |
1_04.txt |
AC |
616 ms |
13428 KB |
1_05.txt |
AC |
31 ms |
12032 KB |
1_06.txt |
AC |
631 ms |
13428 KB |
1_07.txt |
AC |
31 ms |
12032 KB |
1_08.txt |
AC |
617 ms |
13428 KB |
1_09.txt |
AC |
30 ms |
12032 KB |
1_10.txt |
AC |
742 ms |
13428 KB |
1_11.txt |
AC |
32 ms |
12032 KB |
1_12.txt |
AC |
763 ms |
13428 KB |
1_13.txt |
AC |
39 ms |
12032 KB |
1_14.txt |
AC |
617 ms |
13428 KB |
1_15.txt |
WA |
10 ms |
4992 KB |
1_16.txt |
WA |
12 ms |
4992 KB |
1_17.txt |
AC |
40 ms |
11776 KB |
1_18.txt |
WA |
41 ms |
11776 KB |
1_19.txt |
AC |
40 ms |
12032 KB |
1_20.txt |
AC |
37 ms |
11392 KB |
1_21.txt |
WA |
39 ms |
11904 KB |
1_22.txt |
WA |
38 ms |
11648 KB |
1_23.txt |
AC |
39 ms |
11648 KB |
1_24.txt |
WA |
40 ms |
11264 KB |
1_25.txt |
AC |
39 ms |
11776 KB |
1_26.txt |
WA |
40 ms |
11520 KB |
1_27.txt |
AC |
734 ms |
13172 KB |
1_28.txt |
AC |
590 ms |
13172 KB |
1_29.txt |
AC |
580 ms |
12660 KB |
1_30.txt |
AC |
600 ms |
13172 KB |
1_31.txt |
AC |
571 ms |
12788 KB |