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(0); } ans.push_back(z); b.erase(b.begin() + z); } reverse(ans.begin(), ans.end()); for(int x : ans){ cout << x + 1 << '\n'; } }
### 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. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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(0); } ans.push_back(z); b.erase(b.begin() + z); } reverse(ans.begin(), ans.end()); for(int x : ans){ cout << x + 1 << '\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) { printf("%d\n",-1); exit(0); } else b[i]=a[ans],a[ans]=0; } for (int i=n;i>=1;i--) printf("%d\n",b[i]); }
### 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 b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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) { printf("%d\n",-1); exit(0); } else b[i]=a[ans],a[ans]=0; } for (int i=n;i>=1;i--) printf("%d\n",b[i]); } ```
#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]==j) { a[i]=b[j];flag=1; for(int k=j;k<len;k++)b[k]=b[k+1]; break; } if(!flag)return puts("-1"),0;len--; } for(int i=1;i<=n;i++)printf("%d\n",a[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. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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]==j) { a[i]=b[j];flag=1; for(int k=j;k<len;k++)b[k]=b[k+1]; break; } if(!flag)return puts("-1"),0;len--; } for(int i=1;i<=n;i++)printf("%d\n",a[i]); } ```
#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++){ ans.insert(ans.begin()+b[i],b[i]); } for(int i=1;i<=N;i++){ cout << ans[i] << 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 length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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++){ ans.insert(ans.begin()+b[i],b[i]); } for(int i=1;i<=N;i++){ cout << ans[i] << endl; } } ```
#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; } if(b[i] == i+1) { a.push_back(b[i]); b.erase(b.begin()+i); break; } } } for(int i = n-1; i >= 0; --i) { cout << a[i] << '\n'; } }
### 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 length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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; } if(b[i] == i+1) { a.push_back(b[i]); b.erase(b.begin()+i); break; } } } for(int i = n-1; i >= 0; --i) { cout << a[i] << '\n'; } } ```
#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 - 1] = a[i]; for (int j = i; j + 1 < n; j++) a[j] = a[j + 1]; n--; } if (n > 0) { printf("%d\n", -1); return 0; } for (int i = 0; i < N; i++) printf("%d\n", ans[i]); return 0; }
### 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 length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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 - 1] = a[i]; for (int j = i; j + 1 < n; j++) a[j] = a[j + 1]; n--; } if (n > 0) { printf("%d\n", -1); return 0; } for (int i = 0; i < N; i++) printf("%d\n", ans[i]); return 0; } ```
#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++) printf("%d\n",Ans[i]); 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 length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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++) printf("%d\n",Ans[i]); return 0; } ```
#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]; b.erase(b.begin()+j); break; } } } if(a[n-1]!=1) { cout << -1 << endl; } else { for(int i=n-1; i>=0; i--) { cout << a[i] << endl; } } }
### 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 sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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]; b.erase(b.begin()+j); break; } } } if(a[n-1]!=1) { cout << -1 << endl; } else { for(int i=n-1; i>=0; i--) { cout << a[i] << endl; } } } ```
#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 == -1) { cout << -1; return 0; } ans.insert(ans.begin(), z); b.erase(b.begin()+z); } for (int i = 0; i < ans.size(); ++i) { cout << ans[i]+1 << endl; } }
### 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 length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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 == -1) { cout << -1; return 0; } ans.insert(ans.begin(), z); b.erase(b.begin()+z); } for (int i = 0; i < ans.size(); ++i) { cout << ans[i]+1 << endl; } } ```
#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;break;} x.insert(x.begin()+num[i]-1,num[i]); } if(!flag)printf("-1\n"); else { for(int k:x)printf("%d\n",k); } }
### 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 length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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;break;} x.insert(x.begin()+num[i]-1,num[i]); } if(!flag)printf("-1\n"); else { for(int k:x)printf("%d\n",k); } } ```
#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]==s) cur=j; } if (cur&&num[cur]<=i) { ans[i]=num[cur]; in[cur]=0; } else { puts("-1"); return 0; } } for(int i=1;i<=n;i++) printf("%d\n",ans[i]); 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 sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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]==s) cur=j; } if (cur&&num[cur]<=i) { ans[i]=num[cur]; in[cur]=0; } else { puts("-1"); return 0; } } for(int i=1;i<=n;i++) printf("%d\n",ans[i]); return 0; } ```
#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; } b[i]=a[rm]; a[rm]=0; } reverse(b.begin(),b.end()); for(auto x:b) cout<<x<<endl; } /* 1 2 1 2 1 2 3 3 2 1 2 2 3 3 */
### 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 length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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; } b[i]=a[rm]; a[rm]=0; } reverse(b.begin(),b.end()); for(auto x:b) cout<<x<<endl; } /* 1 2 1 2 1 2 3 3 2 1 2 2 3 3 */ ```
#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)==b[j]) { //cout<<b[j]<<"を挿入"<<endl; ans.push(j+1); b.erase(b.begin()+j);; break; } } } for(int i=0;i<N;i++) { cout<<ans.top()<<endl; ans.pop(); } 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 sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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)==b[j]) { //cout<<b[j]<<"を挿入"<<endl; ans.push(j+1); b.erase(b.begin()+j);; break; } } } for(int i=0;i<N;i++) { cout<<ans.top()<<endl; ans.pop(); } return 0; } ```
#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 0; } ans.push_back(target); b.erase(b.begin() + target - 1); } for (int i = N - 1; i >= 0;i--)cout << ans[i] << endl; 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 length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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 0; } ans.push_back(target); b.erase(b.begin() + target - 1); } for (int i = N - 1; i >= 0;i--)cout << ans[i] << endl; return 0; } ```
#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 sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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]); } ```
#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()); tmp.pop(); } } else{ tmp.push(num); } } if(tmp.empty()){ while(!ans.empty()){ cout << (ans.top()) << "\n"; ans.pop(); } } else{ cout << -1; } return 0; }
### 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 length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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()); tmp.pop(); } } else{ tmp.push(num); } } if(tmp.empty()){ while(!ans.empty()){ cout << (ans.top()) << "\n"; ans.pop(); } } else{ cout << -1; } return 0; } ```
#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,n,1){ int po=0; fd(l,i,1)if(a[l]==l){ po=l; break; } fo(l,po,i-1)a[l]=a[l+1]; if(!po){ ok=0; break; } p[i]=po; } if(!ok)puts("-1"); else fo(i,1,n)printf("%d\n",p[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 length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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,n,1){ int po=0; fd(l,i,1)if(a[l]==l){ po=l; break; } fo(l,po,i-1)a[l]=a[l+1]; if(!po){ ok=0; break; } p[i]=po; } if(!ok)puts("-1"); else fo(i,1,n)printf("%d\n",p[i]); } ```
// 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.insert(ans.begin()+v[i]-1, v[i]); } for(int i=0;i<n;i++) cout << ans[i] << endl; return 0; }
### 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 length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp // 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.insert(ans.begin()+v[i]-1, v[i]); } for(int i=0;i<n;i++) cout << ans[i] << endl; return 0; } ```
#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]; for (int j=pos;j<i;j++) a[j]=a[j+1]; } for (int i=1;i<=n;i++) printf("%d\n",c[i]); 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 length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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]; for (int j=pos;j<i;j++) a[j]=a[j+1]; } for (int i=1;i<=n;i++) printf("%d\n",c[i]); return 0; } ```
#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 length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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; } ```
#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+1]; pos++; } }else break; } if (n) cout<<-1<<endl; else { for (int i=ans.size()-1; i>=0; i--) cout<<ans[i]<<" "; cout<<endl; } return 0; }
### 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 length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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+1]; pos++; } }else break; } if (n) cout<<-1<<endl; else { for (int i=ans.size()-1; i>=0; i--) cout<<ans[i]<<" "; cout<<endl; } return 0; } ```
#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; } } if (N==befN){ cout << -1 << endl; return 0; } } for (int i=ans.size()-1; i>=0; i--){ cout << ans[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 length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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; } } if (N==befN){ cout << -1 << endl; return 0; } } for (int i=ans.size()-1; i>=0; i--){ cout << ans[i] << endl; } } ```
#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; ++k) { b[k] = b[k + 1]; } is = true; break; } } if (!is) { puts("-1"); return 0; } } for (int i = 1; i <= n; ++i) { printf("%d\n", a[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. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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; ++k) { b[k] = b[k + 1]; } is = true; break; } } if (!is) { puts("-1"); return 0; } } for (int i = 1; i <= n; ++i) { printf("%d\n", a[i]); } } ```
#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("-1\n"); else for(i=1;i<=n;i++) printf("%d\n",ans[i]); 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 sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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("-1\n"); else for(i=1;i<=n;i++) printf("%d\n",ans[i]); return 0; } ```
#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){ ans[i] = j+1; a.erase( a.begin()+j); break; } } } for(int i=0;i<N;i++){ cout<<ans[i]<<endl; } }
### 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 sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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){ ans[i] = j+1; a.erase( a.begin()+j); break; } } } for(int i=0;i<N;i++){ cout<<ans[i]<<endl; } } ```
#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; return 0; p: l.erase(j); c[i] = k; } for (int i = 0; i < n; i++) cout << c[i] << '\n'; cout << flush; 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 b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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; return 0; p: l.erase(j); c[i] = k; } for (int i = 0; i < n; i++) cout << c[i] << '\n'; cout << flush; return 0; } ```
#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); ret.push_back(i+1); break; } if(i==-1)return puts("-1"),0; n--; } while(ret.size()){ printf("%d\n",ret.back()); ret.pop_back(); } return 0; }
### 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 length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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); ret.push_back(i+1); break; } if(i==-1)return puts("-1"),0; n--; } while(ret.size()){ printf("%d\n",ret.back()); ret.pop_back(); } return 0; } ```
#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; } else if (a[i] == i) { ret[k] = i; a.erase(a.begin() + i); break; } } } for (int i = 1; i <= n; i++) { cout << ret[i] << '\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. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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; } else if (a[i] == i) { ret[k] = i; a.erase(a.begin() + i); break; } } } for (int i = 1; i <= n; i++) { cout << ret[i] << '\n'; } return 0; } ```
#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.begin()+i); break; } } } if(ans.size() == n){ for(int i=n-1; i>=0; i--){ cout << ans[i] << endl; } }else{ cout << -1 << 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 b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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.begin()+i); break; } } } if(ans.size() == n){ for(int i=n-1; i>=0; i--){ cout << ans[i] << endl; } }else{ cout << -1 << endl; } return 0; } ```
#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=true; v.push_back(i+1); a.erase(a.begin()+i); break; } } if(!ok) {fok = false; break;} } if(fok){ for(int i=n-1;i>=0;i--) cout<<v[i]<<endl; } else cout<<"-1"; }
### 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 N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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=true; v.push_back(i+1); a.erase(a.begin()+i); break; } } if(!ok) {fok = false; break;} } if(fok){ for(int i=n-1;i>=0;i--) cout<<v[i]<<endl; } else cout<<"-1"; } ```
#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) { ans[n-i+1]=j; fo(k,j,b0-1) b[k]=b[k+1]; b0--; break; } } if (b0) puts("-1"); else fo(i,1,n) printf("%d\n",ans[i]); }
### 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 N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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) { ans[n-i+1]=j; fo(k,j,b0-1) b[k]=b[k+1]; b0--; break; } } if (b0) puts("-1"); else fo(i,1,n) printf("%d\n",ans[i]); } ```
#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(); for(int j=0;j<(b-1);j++) { it++; } v.insert(it, b); } for(auto i: v) { cout << i << 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. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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(); for(int j=0;j<(b-1);j++) { it++; } v.insert(it, b); } for(auto i: v) { cout << i << endl; } return 0; } ```
#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]==j&&a[j]>a[pos]) pos=j; ans[i]=pos; for(int j=pos;j<i;j++) a[j]=a[j+1]; for(int j=1;j<i;j++) if(a[j]>=i) { printf("-1\n"); return 0; } } for(int i=1;i<=n;i++) printf("%d\n",ans[i]); }
### 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 sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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]==j&&a[j]>a[pos]) pos=j; ans[i]=pos; for(int j=pos;j<i;j++) a[j]=a[j+1]; for(int j=1;j<i;j++) if(a[j]>=i) { printf("-1\n"); return 0; } } for(int i=1;i<=n;i++) printf("%d\n",ans[i]); } ```
#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.erase(v.begin()+j); break; } } if(ok==false){ cout<<"-1"<<endl; return 0; } } for(int i=ans.size()-1;i>=0;i--)cout<<ans[i]<<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 length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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.erase(v.begin()+j); break; } } if(ok==false){ cout<<"-1"<<endl; return 0; } } for(int i=ans.size()-1;i>=0;i--)cout<<ans[i]<<endl; return 0; } ```
#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){ reverse(ans.begin(),ans.end()); for(auto x:ans)cout << x << endl; }else{ cout << -1 << endl; } }
### 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 sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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){ reverse(ans.begin(),ans.end()); for(auto x:ans)cout << x << endl; }else{ cout << -1 << endl; } } ```
#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;} i--; if(itr==B.begin())break; itr--; } if(OK==false){cout<<-1;return 0;} } for(int i=N-1;i>=0;i--)cout<<ans[i]<<endl; }
### 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 sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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;} i--; if(itr==B.begin())break; itr--; } if(OK==false){cout<<-1;return 0;} } for(int i=N-1;i>=0;i--)cout<<ans[i]<<endl; } ```
#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 << -1 << endl; return 0; } r[i] = p+1; v.erase(v.begin()+p); } for (int i = 0; i < N; i++) cout << r[i] << endl; }
### 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 N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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 << -1 << endl; return 0; } r[i] = p+1; v.erase(v.begin()+p); } for (int i = 0; i < N; i++) cout << r[i] << endl; } ```
#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]; } j=0; } } if(k==0){ cout << -1; return 0; } } for(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 b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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]; } j=0; } } if(k==0){ cout << -1; return 0; } } for(i=0; i<n; i++){ cout << ans[i] << endl; } } ```
#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); } ans[x]=Max; x--; for(int j=Max;j<=n-i;j++){ a[j]=a[j+1]; } } for(int i=1;i<=n;i++) printf("%d\n",ans[i]); 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. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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); } ans[x]=Max; x--; for(int j=Max;j<=n-i;j++){ a[j]=a[j+1]; } } for(int i=1;i<=n;i++) printf("%d\n",ans[i]); return 0; } ```
#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.begin()+n); } reverse(ans.begin(), ans.end()); for(int x : ans) cout << x << endl; } int main() { cin >> N; A.resize(N); for(int i=0;i<N;++i) cin >> A[i]; solve(); 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 sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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.begin()+n); } reverse(ans.begin(), ans.end()); for(int x : ans) cout << x << endl; } int main() { cin >> N; A.resize(N); for(int i=0;i<N;++i) cin >> A[i]; solve(); return 0; } ```
#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 ret=solve(a); ans.push_back(i); return ret; } return false; }; if(solve(a)) { for(auto x:ans) printf("%d\n",x+1); } else puts("-1"); 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 length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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 ret=solve(a); ans.push_back(i); return ret; } return false; }; if(solve(a)) { for(auto x:ans) printf("%d\n",x+1); } else puts("-1"); return 0; } ```
#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) { printf("-1\n"); return 0; } v.push_back(r); for (int j = r; j < i; j++)d[j] = d[j + 1]; } for (int i = num - 1; i >= 0; i--)printf("%d\n", v[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. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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) { printf("-1\n"); return 0; } v.push_back(r); for (int j = r; j < i; j++)d[j] = d[j + 1]; } for (int i = num - 1; i >= 0; i--)printf("%d\n", v[i]); } ```
#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 b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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; } ```
#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; } } a[N-1-i] = maxj; for (k=maxj;k<N-i;++k) { b[k-1] = b[k]; } } for (i=0;i<N;++i) { cout << a[i] << 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. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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; } } a[N-1-i] = maxj; for (k=maxj;k<N-i;++k) { b[k-1] = b[k]; } } for (i=0;i<N;++i) { cout << a[i] << endl; } return 0; } ```
#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.erase(B.begin()+j); ans[i]=j+1; break; } } }for(int i=0;i<N;i++){ cout<<ans[i]<<endl; } }
### 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 length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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.erase(B.begin()+j); ans[i]=j+1; break; } } }for(int i=0;i<N;i++){ cout<<ans[i]<<endl; } } ```
#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+1); for(int i=p;i+1<s;i++) b.at(i)=b.at(i+1); } for(int i=n-1;i>=0;i--) cout<<a.at(i)<<endl; }
### 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. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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+1); for(int i=p;i+1<s;i++) b.at(i)=b.at(i+1); } for(int i=n-1;i>=0;i--) cout<<a.at(i)<<endl; } ```
#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 <= i; ++j) { if (b[j] == j) { id = j; } } if (id == -1) { puts("-1"); return 0; } del(id); a[i] = id; } for (int i = 1; i <= n; ++i) { printf("%d\n", a[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. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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 <= i; ++j) { if (b[j] == j) { id = j; } } if (id == -1) { puts("-1"); return 0; } del(id); a[i] = id; } for (int i = 1; i <= n; ++i) { printf("%d\n", a[i]); } } ```
#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; } if (i == 1) { cout << -1 << endl; return 0; } } } for (int i = 0; i < n; i++) { cout << a.front() << endl; a.pop_front(); } return 0; }
### 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 sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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; } if (i == 1) { cout << -1 << endl; return 0; } } } for (int i = 0; i < n; i++) { cout << a.front() << endl; a.pop_front(); } return 0; } ```
#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] == i) { ans.push_back(i); b.erase(b.begin() + (i - 1)); break; } } } reverse(ans.begin(), ans.end()); for(int i = 0; i < N; ++i) { cout << ans[i] << '\n'; } 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 length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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] == i) { ans.push_back(i); b.erase(b.begin() + (i - 1)); break; } } } reverse(ans.begin(), ans.end()); for(int i = 0; i < N; ++i) { cout << ans[i] << '\n'; } return 0; } ```
#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 b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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; } } ```
#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]); }else{ cout << -1 << endl; return 0; } } rep(i,n){ cout << a[i] << " "; }cout << 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 sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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]); }else{ cout << -1 << endl; return 0; } } rep(i,n){ cout << a[i] << " "; }cout << endl; return 0; } ```
#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); for(int i=1;i<=n;++i)scanf("%d",&b[i]); if(!check(n))puts("-1"); else for(int i=1;i<=n;++i)printf("%d\n",ans[i]); }
### 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 sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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); for(int i=1;i<=n;++i)scanf("%d",&b[i]); if(!check(n))puts("-1"); else for(int i=1;i<=n;++i)printf("%d\n",ans[i]); } ```
#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; for(int k=add;k<=i;k++){ a[k]=a[k+1]; } } } for(int i=0;i<n;i++){ cout<<ans[i]<<endl; } }
### 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 length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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; for(int k=add;k<=i;k++){ a[k]=a[k+1]; } } } for(int i=0;i<n;i++){ cout<<ans[i]<<endl; } } ```
#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 length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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; } ```
#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))=b.at(i); index.erase(index.begin()+b.at(i)-1); } for(int i=0;i<N;i++){ cout << ans.at(i) << 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 length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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))=b.at(i); index.erase(index.begin()+b.at(i)-1); } for(int i=0;i<N;i++){ cout << ans.at(i) << endl; } return 0; } ```
#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 length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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]); } ```
#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; } ans.insert(ans.begin()+a[i]-1,a[i]); } for(int i:ans) cout << i << endl; }
### 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 N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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; } ans.insert(ans.begin()+a[i]-1,a[i]); } for(int i:ans) cout << i << endl; } ```
#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 i : b)cout << i << endl; }
### 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 sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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 i : b)cout << i << endl; } ```
#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() + j); break; } } } if(ans.size() == n){ for(int i = n - 1; i >= 0; i--){ cout << ans[i] << endl; } }else{ cout << -1 << 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 length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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() + j); break; } } } if(ans.size() == n){ for(int i = n - 1; i >= 0; i--){ cout << ans[i] << endl; } }else{ cout << -1 << endl; } return 0; } ```
#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[z] == z+1 && arr[z] <= count){ aaa.push_back(z+1); arr.erase(arr.begin()+z); break; } } count--; } for (int z=n-1;z>-1;z--){ cout << aaa[z] << endl; } cin >> 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 length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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[z] == z+1 && arr[z] <= count){ aaa.push_back(z+1); arr.erase(arr.begin()+z); break; } } count--; } for (int z=n-1;z>-1;z--){ cout << aaa[z] << endl; } cin >> n; } ```
#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--; it++; } if(*it > j){ printf("-1\n"); return 0; }else{ a[i] = *it; b.erase(it); } } for (int i = 0; i < N; ++i) printf("%d\n", a[i]); return 0; }
### 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 sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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--; it++; } if(*it > j){ printf("-1\n"); return 0; }else{ a[i] = *it; b.erase(it); } } for (int i = 0; i < N; ++i) printf("%d\n", a[i]); return 0; } ```
#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) return !printf("-1\n"); ans[i] = k; for(int j = k, mx = n - i + 1; j < mx; j++) A[j] = A[j + 1]; } for(int i = n; i; i--) printf("%d\n", ans[i]); 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. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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) return !printf("-1\n"); ans[i] = k; for(int j = k, mx = n - i + 1; j < mx; j++) A[j] = A[j + 1]; } for(int i = n; i; i--) printf("%d\n", ans[i]); return 0; } ```
#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; } a.insert(a.begin()+b[i]-1,b[i]); } for (auto i:a) { cout<<i<<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 sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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; } a.insert(a.begin()+b[i]-1,b[i]); } for (auto i:a) { cout<<i<<endl; } return 0; } ```
#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(num[j]==j+1) { dd=1; s.push(j+1); chg(j,n-i-1); break; } } if(dd==0) { printf("-1"); return 0; } } while(!s.empty()) { printf("%d\n",s.top()); s.pop(); } }
### 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 N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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(num[j]==j+1) { dd=1; s.push(j+1); chg(j,n-i-1); break; } } if(dd==0) { printf("-1"); return 0; } } while(!s.empty()) { printf("%d\n",s.top()); s.pop(); } } ```
#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; if(now == -1) break; b.erase(b.begin()+now-1); } if(now == -1) cout << now << endl; else{ for(int i = n-1; i >= 0; i--){ cout << a.at(i) << 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 length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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; if(now == -1) break; b.erase(b.begin()+now-1); } if(now == -1) cout << now << endl; else{ for(int i = n-1; i >= 0; i--){ cout << a.at(i) << endl; } } } ```
#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()+i); break; } if(i==-1){ cout << "-1" << endl; return 0; } } for(i=0;i<n;i++) cout << res[i] << 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 sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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()+i); break; } if(i==-1){ cout << "-1" << endl; return 0; } } for(i=0;i<n;i++) cout << res[i] << endl; return 0; } ```
#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 << endl; return 0; } b.erase(b.begin() + p); ans[N - i - 1] = p+1; } for (int i = 0; i < N; i++) { cout << ans[i] << endl; } }
### 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 length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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 << endl; return 0; } b.erase(b.begin() + p); ans[N - i - 1] = p+1; } for (int i = 0; i < N; i++) { cout << ans[i] << endl; } } ```
#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 (a[j]==j) { k=j; break; } if (!k){ puts("-1"); return 0; } res[i]=k; rep(j,k,n-i) a[j]=a[j+1]; } for (int i=n; i; i--) printf("%d\n",res[i]); 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 length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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 (a[j]==j) { k=j; break; } if (!k){ puts("-1"); return 0; } res[i]=k; rep(j,k,n-i) a[j]=a[j+1]; } for (int i=n; i; i--) printf("%d\n",res[i]); return 0; } ```
#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.erase(A.begin() + i); b = 1; break; } } if (!b) return cout << -1 << "\n", 0; } reverse(ans.begin(), ans.end()); for (auto a : ans) cout << a << "\n"; }
### 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 length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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.erase(A.begin() + i); b = 1; break; } } if (!b) return cout << -1 << "\n", 0; } reverse(ans.begin(), ans.end()); for (auto a : ans) cout << a << "\n"; } ```
#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[i]; per(j,n,1) { int t=0; per(i,j,1)if(a[i]==i){t=i;break;} if(!t){puts("-1");return 0;} ans[j]=t; rep(i,t,j-1)a[i]=a[i+1]; } rep(i,1,n)cout<<ans[i]<<endl; }
### 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. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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[i]; per(j,n,1) { int t=0; per(i,j,1)if(a[i]==i){t=i;break;} if(!t){puts("-1");return 0;} ans[j]=t; rep(i,t,j-1)a[i]=a[i+1]; } rep(i,1,n)cout<<ans[i]<<endl; } ```
#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 length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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; } ```
#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){ puts("-1"); return 0; } } for (int i = 1; i <= N; i++) printf ("%d\n", B[i]); return 0; }
### 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 sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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){ puts("-1"); return 0; } } for (int i = 1; i <= N; i++) printf ("%d\n", B[i]); return 0; } ```
#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; else {for(int i=n-1;i>=0;i--)cout << a[i]<<endl;} }
### 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 N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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; else {for(int i=n-1;i>=0;i--)cout << a[i]<<endl;} } ```
#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; } } return false; } int main(void){ cin>>N; for(int i=0;i<N;i++) cin>>b[i]; if(check()) for(int i=n-1;i>=0;i--) cout<<a[i]<<endl; else 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 N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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; } } return false; } int main(void){ cin>>N; for(int i=0;i<N;i++) cin>>b[i]; if(check()) for(int i=n-1;i>=0;i--) cout<<a[i]<<endl; else cout<<-1<<endl; return 0; } ```
#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 (auto it = b.begin(); it != b.end(); it++) { std::cout << *it << std::endl; } 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 length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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 (auto it = b.begin(); it != b.end(); it++) { std::cout << *it << std::endl; } return 0; } ```
#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) { cout << -1 << endl; return 0; } a.push_back(r); for(int j = r; j < i; ++j) b[j] = b[j+1]; } for(int i = N-1; i >= 0; --i) { std::cout << a[i] << std::endl; } return 0; }
### 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 sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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) { cout << -1 << endl; return 0; } a.push_back(r); for(int j = r; j < i; ++j) b[j] = b[j+1]; } for(int i = N-1; i >= 0; --i) { std::cout << a[i] << std::endl; } return 0; } ```
#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; } ans.push(v[p]); v.erase(v.begin()+p); N--; } while (ans.size() > 0) { cout << ans.top() << endl; ans.pop(); } }
### 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. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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; } ans.push(v[p]); v.erase(v.begin()+p); N--; } while (ans.size() > 0) { cout << ans.top() << endl; ans.pop(); } } ```
#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 <= i) { pv = j; } } } if (pv == -1) { puts("-1"); return 0; } R[i] = w[pv]; vis[pv] = 1; } for (i = 1; i <= n; i++)printf("%d\n", R[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. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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 <= i) { pv = j; } } } if (pv == -1) { puts("-1"); return 0; } R[i] = w[pv]; vis[pv] = 1; } for (i = 1; i <= n; i++)printf("%d\n", R[i]); } ```
// 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()) { cout<<-1<<endl; return 0; } vans.insert(vans.begin()+x,x); //cout<<x<<":"<<vans.size()<<endl; } for (int i=1;i<=n;i++) cout<<vans[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 length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp // 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()) { cout<<-1<<endl; return 0; } vans.insert(vans.begin()+x,x); //cout<<x<<":"<<vans.size()<<endl; } for (int i=1;i<=n;i++) cout<<vans[i]<<endl; } ```
#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==0){ cout<<-1<<endl; return 0; } } for(i=0;i<n;i++) cout<<buf[n-i-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. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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==0){ cout<<-1<<endl; return 0; } } for(i=0;i<n;i++) cout<<buf[n-i-1]<<endl; return 0; } ```
#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; } if(f)cout<<"-1\n",exit(0); } reverse(ans.begin(),ans.end()); for(int i:ans)cout<<i<<'\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 length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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; } if(f)cout<<"-1\n",exit(0); } reverse(ans.begin(),ans.end()); for(int i:ans)cout<<i<<'\n'; } ```
#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); b.erase(b.begin() + j); l--; break; } } } reverse(a.begin(),a.end()); if(a.size() == n){ for(int i=0;i<n;++i)cout << a[i] << endl; }else{ 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 b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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); b.erase(b.begin() + j); l--; break; } } } reverse(a.begin(),a.end()); if(a.size() == n){ for(int i=0;i<n;++i)cout << a[i] << endl; }else{ cout << -1 << endl; } } ```
#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(b[j] + 1); b.erase(b.begin() + j); break; } } } if(b.empty()) { for(int i = N - 1; i >= 0; i--){ cout << a[i] << endl; } }else { cout << -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 b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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(b[j] + 1); b.erase(b.begin() + j); break; } } } if(b.empty()) { for(int i = N - 1; i >= 0; i--){ cout << a[i] << endl; } }else { cout << -1; } } ```
#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) { ans[++an]=a[i]; for (int j=i; j<=n; j++) s[j]++; bo[i]=1; fl=1; break; } if (!fl) return puts("-1"),0; } for (int i=1; i<=an; i++) printf("%d\n",ans[i]); return 0; }
### 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 length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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) { ans[++an]=a[i]; for (int j=i; j<=n; j++) s[j]++; bo[i]=1; fl=1; break; } if (!fl) return puts("-1"),0; } for (int i=1; i<=an; i++) printf("%d\n",ans[i]); return 0; } ```
#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],b[i]);} } reverse(a.begin(),a.end()); for(int i=0;i<N;i++){cout << a[i] << endl;} }
### 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 length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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],b[i]);} } reverse(a.begin(),a.end()); for(int i=0;i<N;i++){cout << a[i] << endl;} } ```
#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.erase(bs.begin()+j); break; } } } for(int i=1;i<=N;i++){ printf("%d\n",seq[i]); } 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 b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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.erase(bs.begin()+j); break; } } } for(int i=1;i<=N;i++){ printf("%d\n",seq[i]); } return 0; } ```
#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++) a[k] = a[k + 1]; ans[i] = j, --len, flag = 0; break; } if(flag) { puts("-1"); return 0; } } for(int i = 1; i <= n; i++) printf("%d\n", ans[i]); return 0; }
### 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 length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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++) a[k] = a[k + 1]; ans[i] = j, --len, flag = 0; break; } if(flag) { puts("-1"); return 0; } } for(int i = 1; i <= n; i++) printf("%d\n", ans[i]); return 0; } ```
#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 == b[k]){ a[i] = k+1; break; } if(k == 0) return cout << -1 << endl, 0; } repp(k,a[i],i+1) b[k-1] = b[k]; } repp(i,0,N) cout << a[i] << endl; 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 length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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 == b[k]){ a[i] = k+1; break; } if(k == 0) return cout << -1 << endl, 0; } repp(k,a[i],i+1) b[k-1] = b[k]; } repp(i,0,N) cout << a[i] << endl; return 0; } ```
#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"); return 0;} for(int j=k; j<=n; ++j)--x[j]; y[k]=0; s[++s[0]]=b[k]; } for(int i=n; i>=1; --i)printf("%d\n",s[i]); 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 N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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"); return 0;} for(int j=k; j<=n; ++j)--x[j]; y[k]=0; s[++s[0]]=b[k]; } for(int i=n; i>=1; --i)printf("%d\n",s[i]); return 0; } ```
#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; } if (k == -1) { cout << "-1\n"; return 0; } ans.push_back(k); b.erase(b.begin() + k); } for (auto it = ans.rbegin(); it != ans.rend(); it++) cout << 1 + *it << endl; }
### 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 N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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; } if (k == -1) { cout << "-1\n"; return 0; } ans.push_back(k); b.erase(b.begin() + k); } for (auto it = ans.rbegin(); it != ans.rend(); it++) cout << 1 + *it << endl; } ```
#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; return 0; } ans.push_back(z); b.erase(b.begin() + z); } reverse(ans.begin(), ans.end()); for (int i=0; i<n; i++) cout<<1+ans[i]<<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 b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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; return 0; } ans.push_back(z); b.erase(b.begin() + z); } reverse(ans.begin(), ans.end()); for (int i=0; i<n; i++) cout<<1+ans[i]<<endl; return 0; } ```
#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]; } for(int i=n;i>=1;--i) printf("%d\n",a[i]); 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 sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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]; } for(int i=n;i>=1;--i) printf("%d\n",a[i]); return 0; } ```
#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 puts("-1"),0; ans[n-i+1]=a[x],del[x]=1; rep (j,x+1,n) if (!del[j]) p[j]--; } rep (i,1,n) printf("%d\n",ans[i]); 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 length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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 puts("-1"),0; ans[n-i+1]=a[x],del[x]=1; rep (j,x+1,n) if (!del[j]) p[j]--; } rep (i,1,n) printf("%d\n",ans[i]); return 0; } ```
#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.push_back(t); break; } --t; } if (!t) break; } if (ans.size() != n) cout << -1 << endl; else { for (int i = n - 1; i >= 0; --i) cout << ans[i] << endl; } 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 length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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.push_back(t); break; } --t; } if (!t) break; } if (ans.size() != n) cout << -1 << endl; else { for (int i = n - 1; i >= 0; --i) cout << ans[i] << endl; } return 0; } ```
#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[i]); for (int j=i; j<n; j++) { c[j]++; } i=n; } } 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 b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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[i]); for (int j=i; j<n; j++) { c[j]++; } i=n; } } return 0; } ```
#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) { vis[j]=1,ans[i]=a[j]; break; } } if(!ans[i]) { puts("-1"); return 0; } } for(int i=n;i>=1;i--) printf("%d\n",ans[i]); 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 length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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) { vis[j]=1,ans[i]=a[j]; break; } } if(!ans[i]) { puts("-1"); return 0; } } for(int i=n;i>=1;i--) printf("%d\n",ans[i]); return 0; } ```
#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 length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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; } ```
#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; else for(int i=0;i<n;i++) cout<<v[i]<<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 length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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; else for(int i=0;i<n;i++) cout<<v[i]<<endl; } ```
#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; rlt.push_back(k + 1), b.erase(b.begin() + k); } reverse(rlt.begin(), rlt.end()); for (int i = 0; i < rlt.size(); i ++) printf("%d\n", rlt[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 length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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; rlt.push_back(k + 1), b.erase(b.begin() + k); } reverse(rlt.begin(), rlt.end()); for (int i = 0; i < rlt.size(); i ++) printf("%d\n", rlt[i]); } ```
#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.begin()+i); break; } } } for(auto a:ans)cout << a << 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. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it. Constraints * All values in input are integers. * 1 \leq N \leq 100 * 1 \leq b_i \leq N Input Input is given from Standard Input in the following format: N b_1 \dots b_N Output If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted. Examples Input 3 1 2 1 Output 1 1 2 Input 2 2 2 Output -1 Input 9 1 1 1 2 2 1 2 3 2 Output 1 2 2 3 1 2 2 1 1 ### Response ```cpp #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.begin()+i); break; } } } for(auto a:ans)cout << a << endl; return 0; } ```