# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
44106 |
2018-03-29T23:34:25 Z |
imaxblue |
Shift (POI11_prz) |
C++17 |
|
511 ms |
37032 KB |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pii pair<int, int>
#define p3i pair<pii, int>
#define pll pair<ll, ll>
#define p3l pair<pll, ll>
#define lseg L, (L+R)/2, N*2+1
#define rseg (L+R)/2+1, R, N*2+2
#define ub upper_bound
#define lb lower_bound
#define pq priority_queue
#define MN 1000000007
#define fox(k, x) for (int k=0; k<x; ++k)
#define fox1(k, x) for (int k=1; k<=x; ++k)
#define foxr(k, x) for (int k=x-1; k>=0; --k)
#define fox1r(k, x) for (int k=x; k>0; --k)
#define ms multiset
#define flood(x) memset(x, 0x3f3f3f3f, sizeof x)
#define drain(x) memset(x, 0, sizeof x)
#define rng() ((rand() << 14)+rand())
#define scan(X) do{while((X=getchar())<'0'); for(X-='0'; '0'<=(_=getchar()); X=(X<<3)+(X<<1)+_-'0');}while(0)
char _;
#define pi 3.14159265358979323846
short n, a[5005], pos[5005], last[2005], c, p;
vector<short> v;
vector<pair<short, char> > ans, ans2;
int main(){
cin >> n;
fox(l, n){
cin >> a[l];
pos[a[l]]=l;
}
fox1(l, n){
if (l==1) continue;
c=0;
p=pos[l];
if (a[(p-1+n)%n]==l-1) continue;
v.clear();
fox(l2, n){
if (a[l2]!=l) v.pb(a[l2]);
}
int spec=0;
ans.pb(mp(n-p, 'a'));
while(v[(p+n-2)%(n-1)]!=l-1){
if (n%2 && v[(p+n-3)%(n-1)]==l-1){
spec=v[l-1];
break;
}
ans.pb(mp(2, 'a'));
c++;
//cout << p << endl;
if (c>n){
cout << "NIE DA SIE";
return 0;
}
p=(p+n-3)%(n-1);
ans.pb(mp(1, 'b'));
}
a[0]=l;
fox(l2, n-1-p) a[l2+1]=v[p+l2];
fox(l2, p){
a[n-p+l2]=v[l2];
}
fox(l, n){
pos[a[l]]=l;
//cout << a[l] << ' ';
}
//cout << endl;
//continue;
//cout << spec << endl;
if (spec!=0){
c=0;
p=pos[spec];
v.clear();
fox(l2, n){
if (a[l2]!=spec) v.pb(a[l2]);
}
ans.pb(mp(n-p, 'a'));
while(v[(p+n-2)%(n-1)]<l){
ans.pb(mp(2, 'a'));
c++;
//cout << p << endl;
if (c>n){
cout << "NIE DA SIE";
return 0;
}
p=(p+n-3)%(n-1);
ans.pb(mp(1, 'b'));
}
a[0]=spec;
fox(l2, n-1-p) a[l2+1]=v[p+l2];
fox(l2, p){
a[n-p+l2]=v[l2];
}
fox(l, n){
pos[a[l]]=l;
//cout << a[l] << ' ';
}
//cout << endl;
}
}
ans.pb(mp(n-pos[1], 'a'));
fox(l, ans.size()){
ans[l].x%=n;
if (ans[l].x==0) continue;
if (ans2.size() && ans2.back().y==ans[l].y){
ans2.back().x=(ans2.back().x+ans[l].x)%n;
if (ans2.back().x==0) ans2.pop_back();
continue;
}
ans2.pb(ans[l]);
}
ans=ans2;
cout << ans.size() << endl;
fox(l, ans.size()){
cout << ans[l].x%n << ans[l].y << ' ';
}
return 0;
}
Compilation message
prz.cpp: In function 'int main()':
prz.cpp:18:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define fox(k, x) for (int k=0; k<x; ++k)
prz.cpp:109:9:
fox(l, ans.size()){
~~~~~~~~~~~~~
prz.cpp:109:5: note: in expansion of macro 'fox'
fox(l, ans.size()){
^~~
prz.cpp:18:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define fox(k, x) for (int k=0; k<x; ++k)
prz.cpp:121:9:
fox(l, ans.size()){
~~~~~~~~~~~~~
prz.cpp:121:5: note: in expansion of macro 'fox'
fox(l, ans.size()){
^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
488 KB |
Output is correct |
3 |
Incorrect |
2 ms |
488 KB |
Expected integer, but "NIE" found |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
488 KB |
Output is correct |
2 |
Correct |
2 ms |
664 KB |
Output is correct |
3 |
Correct |
2 ms |
664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
664 KB |
Output is correct |
2 |
Incorrect |
3 ms |
664 KB |
Expected EOF |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
956 KB |
Output is correct |
2 |
Incorrect |
3 ms |
956 KB |
Expected integer, but "NIE" found |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
2876 KB |
Output is correct |
2 |
Incorrect |
22 ms |
2876 KB |
Liczby nie zostaly posortowane |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
341 ms |
21864 KB |
Output is correct |
2 |
Incorrect |
218 ms |
21864 KB |
Liczby nie zostaly posortowane |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
434 ms |
34800 KB |
Output is correct |
2 |
Incorrect |
253 ms |
34800 KB |
Liczby nie zostaly posortowane |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
511 ms |
37032 KB |
Output is correct |
2 |
Incorrect |
59 ms |
37032 KB |
Expected integer, but "NIE" found |
3 |
Halted |
0 ms |
0 KB |
- |