Submission #803719

# Submission time Handle Problem Language Result Execution time Memory
803719 2023-08-03T05:39:33 Z moel_solution(#10136) Shifty Grid (CCO17_shifty) C++17
25 / 25
81 ms 2096 KB
#include<bits/stdc++.h>
#define ep emplace
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const int inf=1e9+7;
const ll INF=1e18;
int mp[105][105];
int tmp[105];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,m;
    cin>>n>>m;
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
            cin>>mp[i][j];
    vector<pair<int,pi> >rans;
    auto roth=[&](int r,int p)->void
    {
        p=(p%m+m)%m;
        if(p==0)
            return;
        rans.eb(1,pi(r+1,p));
        for(int i=0;i<m;i++)
            tmp[(i+p)%m]=mp[r][i];
        for(int i=0;i<m;i++)
            mp[r][i]=tmp[i];
        return;
    };
    auto rotv=[&](int c,int p)->void
    {
        p=(p%n+n)%n;
        if(p==0)
            return;
        rans.eb(2,pi(c+1,p));
        for(int i=0;i<n;i++)
            tmp[(i+p)%n]=mp[i][c];
        for(int i=0;i<n;i++)
            mp[i][c]=tmp[i];
        return;
    };
    auto find=[&](int x)->pi
    {
        for(int i=0;i<n;i++)
            for(int j=0;j<m;j++)
                if(mp[i][j]==x)
                    return pi(i,j);
        return pi(-1,-1);
    };
    auto find2=[&](int x)->int
    {
        for(int j=0;j<m;j++)
            if(mp[n-1][j]==x)
                return j;
        return -1;
    };
    for(int i=0;i<n-1;i++)
    {
        for(int j=0;j<m;j++)
        {
            int x=i*m+j;
            pi ps=find(x);
            if(ps.fi==i)
            {
                rotv(ps.se,1);
                roth(i+1,1);
                rotv(ps.se,-1);
                ps.fi++,ps.se++;
            }
            roth(ps.fi,j-ps.se);
            roth(ps.fi,1);
            rotv(j,ps.fi-i);
            roth(ps.fi,-1);
            rotv(j,i-ps.fi);
#ifdef LOCAL
            cout<<"RESULT AFTER "<<x<<": "<<endl;
            for(int i=0;i<n;i++,cout<<endl)
                for(int j=0;j<m;j++)
                    cout<<mp[i][j]<<' ';
#endif
        }
    }
    const int z=(n-1)*m;
    auto swp=[&](int i,int j)->void
    {
        if(i==j)
            return;
        roth(n-1,-i);
        rotv(0,n/2);
        roth(n-1,i-j);
        rotv(0,n/2);
        roth(n-1,j-i);
        rotv(0,n/2);
        roth(n-1,i);
        return;
    };
    for(int i=0;i<m;i++)
        swp(i,find2(z+i));
    if(mp[0][0]!=0)
    {
        roth(n-1,1);
        for(int i=0;i<m;i++)
            swp(i,find2(z+i));
    }
#ifdef LOCAL
    cout<<"RESULT: "<<endl;
    for(int i=0;i<n;i++,cout<<endl)
        for(int j=0;j<m;j++)
            cout<<mp[i][j]<<' ';
#endif
    cout<<rans.size()<<'\n';
    for(auto&t:rans)
        cout<<t.fi<<' '<<t.se.fi<<' '<<t.se.se<<'\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 68 ms 1928 KB Output is correct
6 Correct 72 ms 1984 KB Output is correct
7 Correct 67 ms 1988 KB Output is correct
8 Correct 71 ms 1916 KB Output is correct
9 Correct 70 ms 2032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 284 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 68 ms 1928 KB Output is correct
18 Correct 72 ms 1984 KB Output is correct
19 Correct 67 ms 1988 KB Output is correct
20 Correct 71 ms 1916 KB Output is correct
21 Correct 70 ms 2032 KB Output is correct
22 Correct 74 ms 1964 KB Output is correct
23 Correct 67 ms 2096 KB Output is correct
24 Correct 66 ms 2044 KB Output is correct
25 Correct 67 ms 1972 KB Output is correct
26 Correct 81 ms 2000 KB Output is correct
27 Correct 72 ms 1952 KB Output is correct
28 Correct 60 ms 1396 KB Output is correct
29 Correct 71 ms 1380 KB Output is correct
30 Correct 61 ms 1480 KB Output is correct
31 Correct 75 ms 1532 KB Output is correct
32 Correct 61 ms 1464 KB Output is correct
33 Correct 6 ms 660 KB Output is correct
34 Correct 5 ms 660 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 34 ms 1232 KB Output is correct
37 Correct 5 ms 596 KB Output is correct
38 Correct 6 ms 660 KB Output is correct
39 Correct 6 ms 660 KB Output is correct
40 Correct 15 ms 848 KB Output is correct
41 Correct 6 ms 660 KB Output is correct
42 Correct 4 ms 596 KB Output is correct
43 Correct 29 ms 1140 KB Output is correct
44 Correct 4 ms 468 KB Output is correct
45 Correct 28 ms 948 KB Output is correct
46 Correct 11 ms 780 KB Output is correct