답안 #803630

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
803630 2023-08-03T05:11:03 Z moel_solution(#10136) Shifty Grid (CCO17_shifty) C++17
0 / 25
86 ms 2016 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)%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
        }
    }
    int z=n*m-m;
    auto swp=[&](int i,int j)->void
    {
        if(i==j)
            return;
        rotv(i,n/2);
        roth(n-1,i-j);
        rotv(i,n/2);
        roth(n-1,j-i);
        rotv(i,n/2);
        return;
    };
    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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 260 KB Output is correct
4 Incorrect 0 ms 212 KB Contestant's solution is invalid
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 85 ms 2016 KB Output is correct
6 Incorrect 86 ms 2012 KB Contestant's solution is invalid
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 260 KB Output is correct
4 Incorrect 0 ms 212 KB Contestant's solution is invalid
5 Halted 0 ms 0 KB -