output
stringlengths
52
181k
instruction
stringlengths
296
182k
#include <bits/stdc++.h> using namespace std; int main(){ int n; cin >> n; vector<int> b(n); for(int i = 0; i < n; i++){ cin >> b[i]; b[i]--; } vector<int> ans; while(b.size() > 0){ int z = -1; for(int i = 0; i < b.size(); i++){ if(b[i] == i) z = i; } if(z == -1){ cout << -1 << endl; exit(...
### Prompt Generate a Cpp solution to the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of length N...
#include<bits/stdc++.h> using namespace std; const int N=110; int n; int a[N],b[N]; int main() { scanf("%d",&n); for (int i=1;i<=n;i++) { scanf("%d",&a[i]); } for (int i=1;i<=n;i++) { int ans=0,sum=0; for (int j=1;j<=n;j++) if (a[j]) { sum++; if (a[j]==sum) ans=j; } if (!ans) {...
### Prompt Your task is to create a Cpp solution to the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence...
#include <cstdio> #include <algorithm> #include <iostream> #include <queue> #include <cmath> #include <cstring> using namespace std; #define N 105 int b[N],n,a[N]; int main() { scanf("%d",&n); for(int i=1;i<=n;i++)scanf("%d",&b[i]); int len=n; for(int i=n;i;i--) { bool flag=0; for(int j=len;j;j--) if(b[j]==...
### Prompt Generate a CPP solution to the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of length N...
#include<iostream> #include<vector> using namespace std; int main(){ int N; cin >> N; int b[N+1]; for(int i=1;i<=N;i++) cin >> b[i]; vector<int> ans(N); for(int i=1;i<=N;i++){ if(b[i]>i){ cout << -1 << endl; return 0; } } for(int i=1;i<=N;i++){ ...
### Prompt Construct a Cpp code solution to the problem outlined: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of len...
#include <bits/stdc++.h> using namespace std; int main() { int n, b_, ans = 0; vector<int> a, b; cin >> n; for(int i = 0; i < n; ++i) { cin >> b_; b.push_back(b_); } while(b.size()) { for(int i = b.size()-1; i >= 0; --i) { if(b[0] != 1) { cout << -1 << '\n'; return 0; ...
### Prompt Please create a solution in CPP to the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of ...
#include <bits/stdc++.h> using namespace std; const int MX = 100; int a[MX], ans[MX]; int main() { int n; ignore = scanf("%d", &n); for (int i = 0; i < n; i++) ignore = scanf("%d", a + i); int N = n; while (n > 0) { int i = n - 1; while (i >= 0 && a[i] != i + 1) i--; if (i == -1) break; ans[n...
### Prompt Develop a solution in CPP to the problem described below: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of ...
#include<iostream> using namespace std; const int N=110; int n,b[N],p[N],Ans[N]; int main() { cin>>n; for(int i=1;i<=n;i++) cin>>b[i]; for(int i=1;i<=n;i++) { if(b[i]>i) return puts("-1"),0; for(int j=1;j<i;j++) if(p[j]>=b[i]) p[j]++; p[i]=b[i]; } for(int i=1;i<=n;i++) Ans[p[i]]=b[i]; for(int i=1;i<=n;i++)...
### Prompt Please create a solution in Cpp to the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of ...
#include<iostream> #include<algorithm> #include<cmath> #include<vector> #include<map> using namespace std; int main() { int n; cin >> n; vector<int> b(n),a(n); for(int i=0; i<n; i++) { cin >> b[i]; } for(int i=0; i<n; i++) { for(int j=b.size()-1; j>=0; j--) { if(b[j]==j+1) { a[i]=b[j];...
### Prompt Your challenge is to write a Cpp solution to the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequ...
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int> b(N); for (int i = 0; i < N; ++i) { cin >> b[i]; b[i]--; } vector<int> ans; while (b.size() > 0) { int z = -1; for (int i = 0; i < b.size(); ++i) { if (b[i] == i) z = b[i]; } if (z == -...
### Prompt Develop a solution in cpp to the problem described below: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of ...
#include <bits/stdc++.h> using namespace std; #define rep(i,s,t) for(int i=s;i<t;i++) #define pii pair<int,int> #define MAXNUM 111 pii st[MAXNUM];int num[MAXNUM]; int main() { int n;scanf("%d",&n); rep(i,1,n+1)scanf("%d",&num[i]); vector<int> x;int flag=1; rep(i,1,n+1) { if(num[i]>i){flag=0;...
### Prompt In CPP, your task is to solve the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of lengt...
#include <bits/stdc++.h> using namespace std; int num[105],ans[105]; bool in[105]; int main() { memset(in,1,sizeof(in)); int n; scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&num[i]); for(int i=n;i>0;i--) { int cur=0,s=0; for(int j=1;j<=n;j++) if (in[j]) { s++; if (num[j]==...
### Prompt Your challenge is to write a CPP solution to the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequ...
#include <bits/stdc++.h> using namespace std; const int N=1e6+10; int main(){ int n; cin>>n; vector<int>a(n); for(int i=0;i<n;i++)cin>>a[i]; vector<int>b(n); for(int i=0;i<n;i++){ int k=1,rm=-1; for(int j=0;j<n;j++){ if(a[j]==k) rm=j; if(a[j])k++; } if(rm==-1){ cout<<rm<<endl;return 0; } ...
### Prompt Please formulate a cpp solution to the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of ...
#include <iostream> #include <vector> #include <algorithm> #include <stack> using namespace std; int main() { int N;cin>>N; vector<int> b(N); for(int i=0;i<N;++i)cin>>b[i]; stack<int> ans; for(int i=0;i<N;i++) { for(int j=b.size()-1;1;j--) { if(j==-1) { cout<<-1<<endl; return 0; } if((j+1...
### Prompt Your challenge is to write a CPP solution to the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequ...
#include<iostream> #include<vector> using namespace std; int main() { int N; cin >> N; vector<int>b(N), ans; for (auto&& x : b)cin >> x; for (int i = 0; i < N; i++) { int target = -1; for (int j = 0; j < b.size(); j++) { if (j + 1 == b[j])target = j + 1; } if (target == -1) { cout << -1 << endl; return...
### Prompt Please create a solution in CPP to the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of ...
#include <cstdio> #include <vector> std::vector<int> v; int main() { int n; scanf("%d", &n); for(int i = 1; i <= n; i++) { int x; scanf("%d", &x); if(x > i) return 0 * puts("-1"); v.insert(v.begin() + x - 1, x); } for(int i = 0; i < n; i++) printf("%d\n", v[i]); }
### Prompt Your challenge is to write a cpp solution to the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequ...
#include<bits/stdc++.h> using namespace std; int main() { int n; cin >> n; stack<int> s, tmp, ans; for(int i = 0; i < n; ++i){ int num; cin >> num; s.push(num); } while(!s.empty()){ int num = s.top(); s.pop(); if(num == (int)s.size() + 1){ ans.push(num); while(!tmp.empty()){ s.push(tmp.top...
### Prompt Construct a Cpp code solution to the problem outlined: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of len...
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define fo(i,j,l) for(int i=j;i<=l;++i) #define fd(i,j,l) for(int i=j;i>=l;--i) using namespace std; typedef long long ll; const ll N=12e4; int a[N]; int p[N]; int n; int main() { scanf("%d",&n); fo(i,1,n)scanf("%d",&a[i]); int ok=1; fd(i...
### Prompt Develop a solution in cpp to the problem described below: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of ...
// In the name of God #include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> v(n); for(int i=0;i<n;i++) { cin >> v[i]; } vector<int> ans; for(int i=0;i<n;i++) { if(ans.size() < v[i]-1) { cout << -1; exit(0); } ans.i...
### Prompt Construct a CPP code solution to the problem outlined: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of len...
#include<bits/stdc++.h> using namespace std; const int maxn=1050; int a[maxn],n,tmp[maxn],c[maxn]; int main(){ cin >> n; for (int i=1;i<=n;i++) cin >> a[i]; for (int i=n;i;i--){ int pos=0; for (int j=1;j<=i;j++) if (a[j]==j) pos=j; if (!pos) {puts("-1");return 0;} c[i]=a[pos...
### Prompt Please create a solution in cpp to the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of ...
#include<bits/stdc++.h> using namespace std; vector<int>v; int n,x,i; int main(){ cin>>n; for(i=0;++i<=n;){ cin>>x; if(x>i) return 0*puts("-1"); v.insert(v.begin()+x-1,x); } for(i=-1;++i<n;)cout<<v[i]<<endl; }
### Prompt Please create a solution in CPP to the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of ...
#include <iostream> #include <vector> using namespace std; int main() { int n; cin>>n; int a[101]; for (int i=1; i<=n; i++) cin>>a[i]; vector<int> ans; for(; n>0; n--) { int pos = n; while(pos > 0 && a[pos] != pos) pos--; if (pos > 0) { ans.push_back(pos); while(pos+1 <= n) { a[pos] = a[pos...
### Prompt Construct a CPP code solution to the problem outlined: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of len...
#include <bits/stdc++.h> using namespace std; int main(){ int N; cin >> N; vector<int> b(N), ans; for (int i=0; i<N; i++) cin >> b[i]; while(N>0){ int befN = N; for (int i=N-1; i>=0; i--){ if (b[i]==i+1){ ans.push_back(i+1); b.erase(b.begin()+i); N--; break; ...
### Prompt Please create a solution in Cpp to the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of ...
#include <bits/stdc++.h> using namespace std; int a[110], b[110]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%d", b + i); } for (int i = n; i; --i) { bool is = false; for (int j = i; j; --j) { if (b[j] > j) break; if (b[j] == j) { a[i] = j; for (int k = j; k < i...
### Prompt Generate a cpp solution to the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of length N...
#include <stdio.h> #include <iostream> using namespace std; int a[110],ans[110]; int main(){ int n,i,j,k; scanf("%d",&n); for(i=1;i<=n;i++) scanf("%d",&a[i]); for(k=n;k>=1;k--){ for(i=k;i>=1;i--) if(a[i]==i){ ans[k]=i; break; } if(i==0) break; for(j=i+1;j<=k;j++) a[j-1]=a[j]; } if(k) printf(...
### Prompt Your challenge is to write a CPP solution to the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequ...
#include <bits/stdc++.h> using namespace std; int main(){ int N; cin>>N; vector<int> a(N); for(int i=0;i<N;i++){ cin>>a.at(i); if(a.at(i) > i+1){ cout << -1 << endl; return 0; } } int ans[N]; for(int i=N-1;i>=0;i--){ for(int j=i;j>=0;j--){ if( a.at(j) == j+1){ ...
### Prompt Please provide a Cpp coded solution to the problem described below: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequ...
#include <bits/stdc++.h> using namespace std; int c[111]; int main() { int n; cin >> n; list<int> l; for (int i = 0; i < n; i++) { int b; cin >> b; l.push_back(b); } for (int i = n; i--;) { int k = i + 1; auto j = l.end(); for (; j != l.begin(); k--) if (*--j == k) goto p; cout << -1 << endl; ...
### Prompt Your task is to create a cpp solution to the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence...
#include<cstdio> #include<vector> int n; std::vector <int> ve; std::vector <int> ret; int main(){ #ifdef Ezio freopen("input","r",stdin); #endif scanf("%d",&n); for(int i=0,x;i<n;i++){ scanf("%d",&x); ve.push_back(x); } while(n){ int i; for(i=n-1;~i;i--) if(ve[i]==i+1){ ve.erase(ve.begin()+i); ...
### Prompt Develop a solution in Cpp to the problem described below: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n + 1); for (int i = 1; i <= n; i++) { cin >> a[i]; } vector<int> ret(n + 1); for (int k = n; k >= 1; k--) { for (int i = k; i >= 1; i--) { if (a[i] > i) { cout << -1 << '\n'; return 0; ...
### Prompt Generate a Cpp solution to the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of length N...
#include<bits/stdc++.h> using namespace std; #define ll long long int main(){ int n; cin >> n; vector<int> b(n); for(int i=0; i<n; i++){ cin >> b[i]; } vector<int> ans; for(int j=0; j<n; j++){ for(int i=b.size()-1; i>=0; i--){ if(b[i] == i+1){ ans.push_back(i+1); b.erase(b.b...
### Prompt Your task is to create a CPP solution to the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence...
#include <bits/stdc++.h> typedef long long int ll; using namespace std; const ll MOD = 1e9 + 7; int main() { int n; cin>>n; vector<int> a,v; for(int i=0;i<n;i++){ int x; cin>>x; a.push_back(x); } bool fok=true; for(int i=0;i<n;i++){ bool ok=false; for(int i=a.size()-1;i>=0;i--){ if(a[i]==i+1){ ok=...
### Prompt Create a solution in Cpp for the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of length...
#include<bits/stdc++.h> #define fo(i,a,b) for(int i=a;i<=b;i++) #define fd(i,a,b) for(int i=a;i>=b;i--) using namespace std; typedef long long LL; const int maxn=2e5+5; int n,b[maxn],b0; int ans[maxn]; int main() { scanf("%d",&n); fo(i,1,n) scanf("%d",&b[i]); b0=n; fo(i,1,n) { fd(j,b0,1) if (b[j]==j) { ...
### Prompt Create a solution in cpp for the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of length...
#include <iostream> #include <vector> using namespace std; int main() { int n; cin >> n; vector<int> v; for(int i=0;i<n;i++) { int b; cin >> b; if (b > (i+1)) { cout << -1 << endl; return 0; } // (b-1)番目にbを挿入 auto it = v.begin(); ...
### Prompt Generate a CPP solution to the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of length N...
#include<cstdio> #define maxn 105 int n,a[maxn],cnt[maxn],ans[maxn]; int main() { scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&a[i]); for(int i=1;i<=n;i++) cnt[a[i]]++; for(int i=1;i<=n;i++) if(cnt[i]>n-i+1) { printf("-1\n"); return 0; } for(int i=n;i;i--) { int pos=0; for(int j=1;j<=i;j++) if(a[j]=...
### Prompt Please provide a CPP coded solution to the problem described below: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequ...
#include<bits/stdc++.h> using namespace std; long long n,tmp; bool ok; vector<int> v,ans; int main(){ cin>>n; for(int i=0;i<n;i++){ cin>>tmp; v.push_back(tmp); } for(int i=0;i<n;i++){ ok=false; for(int j=v.size()-1;j>=0;j--){ if((j+1)==v[j]){ ok=true; ans.push_back(v[j]); v.er...
### Prompt Please formulate a CPP solution to the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of ...
#include <bits/stdc++.h> using namespace std; int main(void){ int N; cin >> N; vector<int> b(N+1); vector<int> ans; for(int i=0;i<N;i++)cin >> b[i+1]; for(int i=N;i>=1;i--){ for(int j=i;j>=1;j--){ if(b[j]==j){ ans.push_back(j); b.erase(b.begin()+j); break; } } } if(b.size()==1){ reve...
### Prompt Your challenge is to write a Cpp solution to the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequ...
#include<bits/stdc++.h> using namespace std; int main(){ int N;cin>>N; list<int>B;for(int i=0;i<N;i++){int b;cin>>b;B.push_back(b);} vector<int>ans; while(B.size()){ int i=B.size();bool OK=false; auto itr=B.end();itr--; while(1){ if(*itr==i){ans.push_back(i);B.erase(itr);OK=true;break;} ...
### Prompt Please provide a cpp coded solution to the problem described below: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequ...
#include<bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int> v(N); for (int i = 0; i < N; i++) cin >> v[i]; vector<int> r(N); for (int i = N-1; i >= 0; i--) { int p = -1; for (int j = 0; j < v.size(); j++) { if (v[j] == j+1) p = j; } if (p == -1) { cout ...
### Prompt Create a solution in CPP for the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of length...
#include<bits/stdc++.h> using namespace std; int main(){ int n,i,j,k; cin >> n; vector<int> b(n),ans(n); for(i=0; i<n; i++){ cin >> b[i]; } for(i=n-1; i>=0; i--){ k=0; for(j=i; j>=0; j--){ if(b[j]==j+1){ ans[i]=j+1; for(k=j; k<n-1; k++){ b[k]=b[k+1]; }...
### Prompt Your task is to create a cpp solution to the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence...
#include<bits/stdc++.h> using namespace std; int n,a[105]; int ans[105],x; int Max; int main(){ scanf("%d",&n); x=n; for(int i=1;i<=n;i++) scanf("%d",&a[i]); for(int i=1;i<=n;i++){ Max=0; for(int j=1;j<=n-i+1;j++){ if(a[j]>j){ printf("-1\n"); return 0; } if(a[j]==j) Max=max(Max,j); ...
### Prompt Generate a Cpp solution to the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of length N...
#include <bits/stdc++.h> using namespace std; const int MAX_N = 102; int N; vector<int> A; void solve() { vector<int> ans; while(!A.empty()){ int n = -1; for(int i=0;i<(int)A.size();++i){ if(A[i]==i+1){ n = i; } } if(n==-1){ cout << -1 << endl; return; } ans.push_back(n+1); A.erase(A.b...
### Prompt Your challenge is to write a cpp solution to the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequ...
#include<bits/stdc++.h> using namespace std; int main() { int n;cin>>n; vector<int> a(n); for(int i=0;i<n;i++) cin>>a[i],--a[i]; vector<int> ans; function<bool(vector<int>)> solve=[&](vector<int> a) { if(a.empty()) return true; for(int i=a.size()-1;~i;i--) if(a[i]==i) { a.erase(a.begin()+i); bool r...
### Prompt Please formulate a Cpp solution to the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of ...
#include<stdio.h> #include<vector> #include<algorithm> using namespace std; int d[2020]; int main() { int num; scanf("%d", &num); for (int i = 1; i <= num; i++)scanf("%d", &d[i]); vector<int>v; for (int i = num; i >= 1; i--) { int r = -1; for (int j = 1; j <= i; j++)if (d[j] == j)r = j; if (r == -1) { ...
### Prompt Generate a cpp solution to the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of length N...
#include <bits/stdc++.h> using namespace std; int main(){ int n,x,i;cin>>n; vector<int>v; for(i=1;i<=n;i++){ cin>>x; if(x>i) {cout<<-1<<endl;return 0;} v.insert(v.begin()+x-1,x); } for(auto it:v)cout<<it<<endl; return 0; }
### Prompt Your task is to create a CPP solution to the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence...
#include <iostream> using namespace std; int b[100],a[100]; int main(){ int i,N,j,k,maxj; cin >> N; for (i=0;i<N;++i) { cin >> b[i]; if (b[i]>i+1) { cout << -1 << endl; return 0; } } for (i=0;i<N;++i) { maxj=0; for (j=0;j<N-i;j++) { if (b[j] == j+1) { maxj=j+1;...
### Prompt Generate a CPP solution to the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of length N...
#include<bits/stdc++.h> using namespace std; int main(){ int N;cin>>N; vector<int> B(N);bool flag=true; for(int i=0;i<N;i++){ cin>>B[i]; if(B[i]>i+1){ flag=false; } }if(!flag){ cout<<-1<<endl; return 0; }vector<int> ans(N); for(int i=N-1;i>=0;i--){ for(int j=i;j>=0;j--){ if(B[j]==j+1){ B.era...
### Prompt Develop a solution in CPP to the problem described below: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of ...
#include<bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; vector<int> b(n); for(int i=0;i<n;i++) cin>>b.at(i); vector<int> a; for(int s=n;s>0;s--){ int p=s; for(int i=0;i<s;i++) p=(b.at(i)==i+1?i:p); if(p==s){ cout<<-1<<endl; return 0; } a.push_back(p+...
### Prompt Generate a Cpp solution to the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of length N...
#include <bits/stdc++.h> using namespace std; const int N = 105; int a[N]; int b[N]; void del(int id) { for (int i = id; i < N - 1; ++i) { b[i] = b[i + 1]; } } int main() { int n; cin >> n; for (int i = 1; i <= n; ++i) { cin >> b[i]; } for (int i = n; i > 0; --i) { int id = -1; for (int j = 1; j <=...
### Prompt Generate a Cpp solution to the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of length N...
#include <bits/stdc++.h> using namespace std; int main(void) { int n; cin >> n; vector<int> b(n+1); for (int i = 1; i <= n; i++) { cin >> b[i]; } deque<int> a; while (b.size() != 1) { for (int i = b.size()-1; i >= 1; i--) { if (b[i] == i) { a.push_front(b[i]); b.erase(b.begin() + i); break...
### Prompt Please provide a cpp coded solution to the problem described below: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequ...
#include <bits/stdc++.h> using namespace std; int main(void) { int N; cin >> N; vector<int> b; for(int i = 1; i <= N; ++i) { int t; cin >> t; if(t > i) { cout << "-1\n"; return 0; } b.push_back(t); } vector<int> ans; while(b.size() > 0) { for(int i = b.size(); i >= 1; --i) { if(b[i - 1] ==...
### Prompt Please formulate a Cpp solution to the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of ...
#include<bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; vector<int>ans; for(int i=1;i<=n;i++){ int a; cin>>a; if(a>i){cout<<-1;return 0;} else{ans.insert(ans.begin()+a-1,a);} } for(int i=0;i<n;i++){ cout<<ans[i]<<endl; } }
### Prompt Your task is to create a CPP solution to the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence...
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for(long long int i=0;i<n;++i) typedef long long int ll; int main(){ int n; cin >> n; vector<int> b(n); rep(i,n)cin >> b[i]; vector<int> a; for(int i=0;i<n;i++){ if(b[i]<=i+1){ a.insert(a.begin()+b[i]-1,b[i]);...
### Prompt Your challenge is to write a CPP solution to the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequ...
#include <bits/stdc++.h> using namespace std; int b[1000],ans[1000]; bool check(int n){ if(!n)return 1; for(int i=n;i;--i) if(b[i]==i){ ans[n]=i; for(int j=i;j<n;++j)b[j]=b[j+1]; return check(n-1); } return 0; } int main(){ int n; scanf("%d",&n); ...
### Prompt Please provide a Cpp coded solution to the problem described below: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequ...
#include<iostream> using namespace std; int main(){ int a[100]; int ans[100]; int n; cin>>n; for(int i=0;i<n;i++){ cin>>a[i]; } for(int i=n-1;i>=0;i--){ int add=-1; for(int j=0;j<=i;j++){ if(a[j]==j+1){add=j;}} if(add==-1){cout<<-1<<endl;return 0;} else{ ans[i]=add+1...
### Prompt In cpp, your task is to solve the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of lengt...
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int N,b; cin >> N; vector<int> ans; for(int i=0; i<N; i++){ cin >> b; if(i+1<b){cout << "-1" << endl; return 0;} ans.insert(ans.begin()+b-1,b); } for(int i=0; i<N; i++){ cout << ans[i] << endl; } return 0;...
### Prompt In CPP, your task is to solve the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of lengt...
#include <bits/stdc++.h> using namespace std; int main(){ int N; cin >> N; vector<int> b(N),ans(N),index(N); for(int i=0;i<N;i++){ cin >> b.at(i); index.at(i)=i; } for(int i=N-1;i>=0;i--){ if(index.size()<b.at(i)){ cout << -1 << endl; return 0; } ans.at(index.at(b.at(i)-1))=...
### Prompt Please formulate a Cpp solution to the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of ...
#include<stdio.h> int a[110],s[110]; int main(){ int n,i,j; scanf("%d",&n); for(i=1;i<=n;i++)scanf("%d",a+i); for(i=n;i>0;i--){ for(j=i;j>0;j--){ if(a[j]==j)break; } if(!j){ printf("-1"); return 0; } s[i]=j; for(;j<i;j++)a[j]=a[j+1]; } for(i=1;i<=n;i++)printf("%d ",s[i]); }
### Prompt In cpp, your task is to solve the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of lengt...
#include <bits/stdc++.h> #define int long long using namespace std; int a[10010]; int32_t main() { int n; cin >> n; vector <int> ans; for(int i=1;i<=n;i++) { cin >> a[i]; if(ans.size() < a[i]-1) { cout << -1 << endl; return 0; } ...
### Prompt Create a solution in Cpp for the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of length...
#include<bits/stdc++.h> using namespace std; using ll = long long; int main() { int n; cin >> n; vector<int> a(n), b; for(int i = 0; i < n; i++)cin >> a[i]; for(int i = 0; i < n; i++) { if(a[i] - 1 > (int)b.size()) { cout << -1 << endl; return 0; } b.insert(b.begin() + a[i] - 1, a[i]); } for(auto...
### Prompt Your challenge is to write a Cpp solution to the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequ...
#include<bits/stdc++.h> using namespace std; int main(){ int n; cin >> n; vector<int> b(n); for(int i = 0; i < n; i++) cin >> b[i]; vector<int> ans; for(int i = n - 1; i >= 0; i--){ for(int j = i; j >= 0; j--){ if(b[j] == j + 1){ ans.push_back(j + 1); b.erase(b.begin() +...
### Prompt Please formulate a CPP solution to the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of ...
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main(){ ll n; cin >> n; vector <ll> arr(n); for (int z=0;z<n;z++){ cin >> arr[z]; } vector <ll> aaa; ll count = n; while (arr.size() > 0){ if (count < 0 ){ cout << -1 << endl; return 0; } for (int z=n-1;z>-1;z--){ if (arr[...
### Prompt Develop a solution in Cpp to the problem described below: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of ...
#include<cstdio> #include<list> using namespace std; int main(){ int N; scanf("%d", &N); list<int> b; for (int i = 0; i < N; ++i){ int tmp; scanf("%d", &tmp); b.push_front(tmp); } int a[N]; for (int i = N - 1; i >= 0; --i){ list<int>::iterator it = b.begin(); int j = i + 1; while(*it < j){ j--; ...
### Prompt Please provide a cpp coded solution to the problem described below: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequ...
#include <cstdio> #include <cstring> #include <algorithm> int n; int A[111]; int ans[111]; bool vis[111]; int main(){ scanf("%d", &n); for(int i = 1; i <= n; i++) scanf("%d", &A[i]); for(int i = 1; i <= n; i++){ int k = -1; for(int j = 1, mx = n - i + 1; j <= mx; j++) if(A[j] == j) k = j; if(k == -1) ret...
### Prompt Generate a Cpp solution to the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of length N...
#include <bits/stdc++.h> using namespace std; using ll=long long; const ll MOD=(ll)1e9+7; int main() { int N; cin>>N; vector<int> a,b(N); for (int i = 0; i < N; ++i) { cin>>b[i]; } for (int i = 0; i < N; ++i) { if(i+1<b[i]){ cout<<-1<<endl; return 0; ...
### Prompt Your challenge is to write a cpp solution to the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequ...
#include<bits/stdc++.h> using namespace std; stack<int> s; int num[110]; int n; void chg(int st,int ed) { for(int i=st;i<ed;i++) { num[i]=num[i+1]; } } int main() { scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%d",&num[i]); } for(int i=0;i<n;i++) { int dd=0; for(int j=n-1-i;j>=0;j--) { if(n...
### Prompt Create a solution in CPP for the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of length...
#include <bits/stdc++.h> using namespace std; int main(){ int n; cin >> n; vector<int> b(n); for(int i = 0; i < n; i++) cin >> b.at(i); vector<int> a(n); int now; for(int i = 0; i < n; i++){ now = -1; for(int j = 0; j < n-i; j++){ if(j+1 == b.at(j)) now = j+1; } a.at(i) = now; ...
### Prompt Please formulate a Cpp solution to the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of ...
#include<iostream> #include<vector> using namespace std; int N_MAX = 100; int main() { int n,m,b,i; int res[N_MAX]; vector<int> v; cin >> n; for(i=0;i<n;i++){ cin >> b; v.push_back(b); } for(m=n;m>0;m--){ for(i=m-1;i>=0;i--) if(v[i]==i+1){ res[m-1]=i+1; v.erase(v.begin()+...
### Prompt Your challenge is to write a Cpp solution to the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequ...
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int> b(N); for (int i = 0; i < N; i++) { cin >> b[i]; } vector<int> ans(N, 0); for (int i = 0; i < N; i++) { int p = -1; for (int j = 0; j < b.size(); j++) { if (b[j] == j + 1) p = j; } if (p == -1) { cout << -1 ...
### Prompt In Cpp, your task is to solve the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of lengt...
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #define rep(i,l,r) for (int i=(l); i<=(r); i++) typedef long long ll; using namespace std; const int N=1010; int n,a[N],res[N]; int main(){ scanf("%d",&n); rep(i,1,n) scanf("%d",&a[i]); rep(i,1,n){ int k=0; for (int j=n-i+1; j; j--) if (...
### Prompt In Cpp, your task is to solve the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of lengt...
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int> A(N); for (int i = 0; i < N; i++) cin >> A.at(i); vector<int> ans; while (A.size()) { bool b = 0; for (int i = A.size() - 1; i >= 0; i--) { if (A.at(i) == i + 1) { ans.push_back(A.at(i)); A...
### Prompt Please formulate a Cpp solution to the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of ...
#include<cstdio> #include<algorithm> #include<cstdlib> #include<iostream> #include<cstring> #include<memory.h> #include<map> #include<set> #include<queue> #define rep(i,a,b) for(int i=a;i<=b;i++) #define per(i,a,b) for(int i=a;i>=b;i--) using namespace std; int n,a[105],ans[105]; int main() { cin>>n; rep(i,1,n)cin>>a...
### Prompt Generate a CPP solution to the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of length N...
#include <bits/stdc++.h> using namespace std; int main() { int n,x,i;cin>>n;vector<int>v; for(i=1;i<=n;i++){ cin>>x; if(x>i) {cout<<-1<<endl;return 0;} v.insert(v.begin()+x-1,x); } for(auto it:v)cout<<it<<endl; }
### Prompt Please formulate a Cpp solution to the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of ...
#include <stdio.h> int main() { int N, A[101], B[101]; scanf ("%d", &N); for (int i = 1; i <= N; i++) scanf ("%d", &A[i]); for (int k = N; k >= 1; k--){ bool f = 0; for (int i = k; i >= 1; i--) if (A[i] == i){ for (int j = i + 1; j <= k; j++) A[j - 1] = A[j]; B[k] = i; f = 1; break; } if (!f){ ...
### Prompt Please provide a Cpp coded solution to the problem described below: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequ...
#include<bits/stdc++.h> using namespace std; int main(){ int n; cin >>n; vector<int> b(n),a(n); for(int i=0;i<n;i++)cin>>b[i]; for(int j=0;j<n;j++){ for(int i=b.size()-1;i>=0;i--){ if(i+1==b[i]){ a[j]=b[i]; b.erase(b.begin()+i); break; } } } if(a[n-1]!=1)cout<<-1<<endl; el...
### Prompt Create a solution in CPP for the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of length...
#include <bits/stdc++.h> using namespace std; int a[100]; int n=0; int b[100]; int N; bool check(void){ for(int i=N-1;i>=0;i--){ if(b[i]==i+1){ a[n]=i+1; n+=1; for(int j=i;j<N-1;j++) b[j]=b[j+1]; N-=1; if(N>0){ if(check()==false) return false; } return true; ...
### Prompt Create a solution in cpp for the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of length...
#include <iostream> #include <list> int main() { size_t N; std::cin >> N; std::list<size_t> b; for (size_t i=0; i<N; i++) { size_t a; std::cin >> a; if (a > i+1) { std::cout << -1 << std::endl; return 0; } auto it = std::next(b.begin(), a-1); b.insert(it, a); } for...
### Prompt Please create a solution in Cpp to the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of ...
#include <iostream> #include <algorithm> #include <vector> using namespace std; int main() { int N; cin >> N; vector<int> b(N+1); for(int i = 1; i <= N; ++i) cin >> b[i]; vector<int> a; for(int i = N; i >= 1; --i) { int r = -1; for(int j = 1; j <= i; ++j) if(b[j] == j) r = j; if(r == -1) { ...
### Prompt Please provide a Cpp coded solution to the problem described below: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequ...
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int> v(N); stack<int> ans; for (int &e : v) cin >> e; while (v.size() > 0) { int p = -1; for (int i = 0; i < N; i++) { if (v[i] == i+1) p = i; } if (p < 0) { cout << -1 << endl; return 0;...
### Prompt Generate a CPP solution to the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of length N...
#include<cstdio> #include<algorithm> using namespace std; int n, w[110]; int vis[110], R[110]; int main() { int i, j; scanf("%d", &n); for (i = 1; i <= n; i++)scanf("%d", &w[i]); for (i = 1; i <= n; i++) { int cur = 1, pv = -1; for (j = 1; j <= n; j++) { if (vis[j])cur++; else { if (w[j] == cur && cur...
### Prompt Generate a CPP solution to the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of length N...
// failed to generate code #include <bits/stdc++.h> using namespace std; #define PB push_back #define MP make_pair int main(){ ios::sync_with_stdio(false); int n; cin>>n; vector<int> b(n); for (int i=0;i<n;i++) cin>>b[i]; vector<int> vans; vans.PB(-1); for (int i=0;i<n;i++) { int x=b[i]; if (x>vans.size()) {...
### Prompt Please create a solution in cpp to the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of ...
#include<iostream> #include<vector> using namespace std; int main(){ int n,i,j; cin>>n; vector<int> a(n); for(i=0;i<n;i++){ cin>>a[i]; } int buf[n]; for(i=0;i<n;i++){ for(j=n-i;j>=1;j--){ if(a[j-1]==j){ buf[i]=j; a.erase(a.begin()+j-1); break; } } if(j==...
### Prompt Generate a cpp solution to the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of length N...
#include<bits/stdc++.h> using namespace std; int n,a; vector<int> v; int main() { cin>>n; for(int i=1;i<=n;i++)cin>>a,v.push_back(a-1); vector<int> ans; while(!v.empty()) { bool f=1; for(int i=v.size()-1;i>=0;i--) if(v[i]==i) { ans.push_back(i+1); v.erase(v.begin()+i); f=0; break; } ...
### Prompt Develop a solution in cpp to the problem described below: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of ...
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main(void){ int n,l; vector<int> b; vector<int> a; cin >> n; l = n; for(int i=0;i<n;++i){ int k; cin >> k; b.push_back(k); } for(int i=0;i<n;++i){ for(int j=l-1;j>=0;--j){ if(b[j] == j+1){ a.push_back(j+1); ...
### Prompt Your task is to create a CPP solution to the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence...
#include<bits/stdc++.h> using namespace std; typedef long long ll; int main(){ int N; cin >> N; vector<int> b(N); for(int i = 0; i < N; i++){ cin >> b[i]; b[i]--; } vector<int> a; for(int i = 0; i < N; i++){ for(int j = b.size() - 1; j >= 0; j--){ if(b[j] == j) { a.emplace_back...
### Prompt Your task is to create a Cpp solution to the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence...
#include<bits/stdc++.h> using namespace std; int n,a[101],ans[101],an,s[101]; bool bo[101]; int main() { scanf("%d",&n); for (int i=1; i<=n; i++) scanf("%d",&a[i]); memset(bo,0,sizeof(bo)); memset(s,0,sizeof(s)); for (int T=1; T<=n; T++) { bool fl=0; for (int i=n; i; i--) if (!bo[i]&&s[i]==a[i]-1) { ...
### Prompt Construct a cpp code solution to the problem outlined: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of len...
#include<bits/stdc++.h> using namespace std; int main(){ int N; cin >> N; vector<int> b(N); for(int i=1;i<=N;i++)cin >> b[i]; for(int i=1;i<=N;i++){ if(b[i]>i){cout << -1 << endl; return 0;} } vector<int> a; for(int i=1;i<=N;i++){ if(b[i]==1){a.push_back(1);} else{a.insert(a.begin()+i-b[i],...
### Prompt In CPP, your task is to solve the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of lengt...
#include <cstdio> #include <vector> std::vector<int> bs; int seq[105]; int main(){ int N; scanf("%d",&N); bs.resize(N+1); for(int i=1;i<=N;i++){ scanf("%d",&bs[i]); } for(int t=N;t>0;t--){ for(int j=t;;j--){ if(j==0){ printf("-1\n"); return 0; } if(bs[j]==j){ seq[t]=j; bs.er...
### Prompt Your task is to create a CPP solution to the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence...
#include <bits/stdc++.h> using namespace std; const int N = 200; int n, len; int a[N], ans[N]; bool flag; int main() { scanf("%d", &n), len = n; for(int i = 1; i <= n; i++) scanf("%d", &a[i]); for(int i = n; i; i--) { flag = 1; for(int j = len; j; j--) { if(a[j] != j) continue; for(int k = j; k < len; k++...
### Prompt Construct a CPP code solution to the problem outlined: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of len...
#include <bits/stdc++.h> using namespace std; typedef long long LL; #define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i) #define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i) int main(){ int N; cin >> N; vector<int> a(N),b(N); repp(i,0,N) cin >> b[i]; repm(i,N-1,-1){ repm(k,i,-1){ if(k+1 ...
### Prompt Please create a solution in cpp to the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of ...
#include<bits/stdc++.h> using namespace std; const int N=110; int n,b[N],x[N],y[N],s[N]; int main(){ scanf("%d",&n); for(int i=1; i<=n; ++i) scanf("%d",&b[i]); for(int i=1; i<=n; ++i)x[i]=i,y[i]=1; for(int i=1; i<=n; ++i){ int k=0; for(int j=1; j<=n; ++j)if(b[j]==x[j]&&y[j]==1)k=j; if(k==0){puts("-1"); retu...
### Prompt Create a solution in Cpp for the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of length...
#include <vector> #include <iostream> using namespace std; int main() { int n; cin >> n; vector<int> b(n); for (int i = 0; i < n; i++) cin >> b[i]; vector<int> ans; for (int i = 0; i < n; i++) { int k = -1; for (int j = 0; j < b.size(); j++) { if (j == b[j]-1) k = j; ...
### Prompt Create a solution in cpp for the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of length...
#include<bits/stdc++.h> using namespace std; int main() { int n; cin>>n; vector<int> b(n); for (int i=0; i<n; i++) cin>>b[i], b[i]--; vector<int> ans; while (b.size() > 0) { int z = -1; for (int i = 0; i < b.size(); i++) { if(b[i] == i) z = i; } if( z==-1) { cout << -1 << endl; re...
### Prompt Your task is to create a CPP solution to the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence...
#include <bits/stdc++.h> using namespace std; const int N = 105; int n, b[N], a[N]; int main() { scanf("%d",&n); for(int i=1;i<=n;++i) scanf("%d",b+i); for(int i=1;i<=n;++i) { for(int j=n-i+1;j>=1;--j) if(b[j]==j) { a[i]=j; break; } if(!a[i]) return puts("-1"),0; for(int j=a[i];j<=n-i;++j) b[j]=b[j+1...
### Prompt Your challenge is to write a CPP solution to the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequ...
#include<bits/stdc++.h> #define rep(i,x,y) for (int i=(x);i<=(y);i++) using namespace std; const int N=111; int n,a[N],p[N],del[N],ans[N]; int main(){ scanf("%d",&n); rep (i,1,n) scanf("%d",&a[i]),p[i]=i,del[i]=0; rep (i,1,n){ int cnt=0,x; rep (j,1,n) if (!del[j]&&p[j]==a[j]) cnt++,x=j; if (!cnt) return put...
### Prompt Please create a solution in Cpp to the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of ...
#include <iostream> #include <vector> #include <list> using namespace std; int main() { int n; cin >> n; list<int> b(n); vector<int> ans; for (auto& e : b) cin >> e; while (!b.empty()) { int t = b.size(); for (auto it = b.rbegin(); it != b.rend(); ++it) { if (*it == t) { b.erase(--it.base()); ans....
### Prompt Please create a solution in Cpp to the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of ...
#include <bits/stdc++.h> typedef long long ll; using namespace std; int c[110]; int main() { int n; cin>>n; int b[110]; for (int i=0; i<n; i++) { scanf("%d",b+i); if (b[i]>i+1) { cout<<-1<<endl; return 0; } } for (int i=n-1; i>=0; i--) { if (b[i]==c[i]+1) { printf("%d\n",b...
### Prompt Your task is to create a cpp solution to the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence...
#include<stdio.h> #include<bits/stdc++.h> using namespace std; int n,a[105],vis[105],ans[105]; int main() { scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&a[i]); for(int i=1;i<=n;i++) { for(int j=n;j>=1;j--) { if(vis[j]) continue; int cc=0; for(int k=1;k<j;k++) cc+=(!vis[k]); if(cc==a[j]-1) { ...
### Prompt Please create a solution in CPP to the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of ...
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); int n,x,i;cin>>n; vector<int>v; for(i=1;i<=n;i++){ cin>>x; if(x>i) {cout<<-1<<endl;return 0;} v.insert(v.begin()+x-1,x); } for(auto it:v)cout<<it<<endl; return 0; }
### Prompt Please formulate a Cpp solution to the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of ...
#include <iostream> #include <vector> using namespace std; vector<int>v; int main(void){ int n,b; cin>>n; bool flag=0; for(int i=1;i<=n;i++){ cin>>b; if(b>i){ flag=1; break; } else v.insert(v.begin()+b-1,b); } if(flag) cout<<-1<<endl; ...
### Prompt Construct a cpp code solution to the problem outlined: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of len...
#include <bits/stdc++.h> using namespace std; int n; vector <int> b, rlt; int main() { scanf("%d", &n); b.resize(n); for (int i = 0; i < n; i ++) scanf("%d", &b[i]); while (n --) { int k = n; while (k >= 0 && b[k] != k + 1) k --; if (k < 0) return printf("-1"), 0; r...
### Prompt In cpp, your task is to solve the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of lengt...
#include <bits/stdc++.h> using namespace std; int main(){ int N; cin >> N; vector<int> b(N); vector<int> ans(N); for(auto &k:b)cin >> k; for(int k=0;k<N;k++){ for(int i=b.size()-1;i>=0;i--){ if(b[i]>i+1){ cout << "-1" << endl; return 0; } if(b[i]==i+1){ ans[N-k-1]=i+1; b.erase(b.beg...
### Prompt Generate a cpp solution to the following problem: Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of length N...