Submission #803463

# Submission time Handle Problem Language Result Execution time Memory
803463 2023-08-03T04:33:05 Z moel_solution(#10136) Shifty Grid (CCO17_shifty) C++17
0 / 25
1 ms 212 KB
#include<iostream>
#include<vector>
#include<algorithm>
#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)%n;
        if(p==0)
            return;
        rans.eb(1,pi(r+1,m-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(1,pi(c+1,n-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);
    };
    for(int i=0;i<n-1;i++)
    {
        for(int j=0;j<m;j++)
        {
            int x=i*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);
        }
    }
    int x=(n-1)*m;
    pi ps=find(x);
    roth(ps.fi,-ps.se);
    reverse(all(rans));
    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 Incorrect 1 ms 212 KB Integer parameter [name=i] equals to 4, violates the range [1, 2]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Integer parameter [name=i] equals to 4, violates the range [1, 2]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Integer parameter [name=i] equals to 4, violates the range [1, 2]
2 Halted 0 ms 0 KB -