답안 #804907

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
804907 2023-08-03T11:53:16 Z moe_solution(#10139) Shifty Grid (CCO17_shifty) C++17
15 / 25
66 ms 2440 KB
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
//#include <bits/extc++.h>
//using namespace __gnu_pbds;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
using ll=long long;
using ull=unsigned long long;
using db=long double;
using pii=array<int,2>;
using pll=array<ll,2>;
using pdb=array<db,2>;
using tii=array<int,3>;
using tll=array<ll,3>;
using tdb=array<db,3>;
using ti4=array<int,4>;
using tl4=array<ll,4>;
using td4=array<db,4>;
//using oset=tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//uniform_int_distribution<> gen(1,100);
template <int MOD_> struct modnum{
private:
	int v;
public:
	static const int MOD = MOD_;
	modnum() : v(0) {}
	modnum(ll v_) : v(int(v_ % MOD)) { if (v < 0) v += MOD; }
	explicit operator int () const { return v; }
	friend bool operator == (const modnum& a, const modnum& b) { return a.v == b.v; }
	friend bool operator != (const modnum& a, const modnum& b) { return a.v != b.v; }
	friend bool operator < (const modnum& a, const modnum& b) { return a.v < b.v; }
	friend bool operator <= (const modnum& a, const modnum& b) { return a.v <= b.v; }
	friend bool operator > (const modnum& a, const modnum& b) { return a.v > b.v; }
	friend bool operator >= (const modnum& a, const modnum& b) { return a.v >= b.v; }
	modnum& operator += (const modnum& o) {
		v += o.v;
		if (v >= MOD) v -= MOD;
		return *this;
	}
	modnum& operator -= (const modnum& o) {
		v -= o.v;
		if (v < 0) v += MOD;
		return *this;
	}
	modnum& operator *= (const modnum& o) {
		v = int(ll(v) * ll(o.v) % MOD);
		return *this;
	}
	friend modnum pow(modnum a, ll p) {
		modnum ans = 1;
		for (; p; p /= 2, a *= a) if (p&1) ans *= a;
		return ans;
	}
	modnum operator ~ () const {
		modnum res;
		res.v = pow((modnum)v, MOD - 2).v;
		return res;
	}
	modnum& operator /= (const modnum& o) {
		return *this *= (~o);
	}
	modnum operator-() const { return modnum(-v); }
	modnum& operator++() { return *this += 1; }
	modnum operator++(int){ modnum tmp=*this; ++*this; return tmp; }
	modnum& operator--() { return *this -= 1; }
	modnum operator--(int){ modnum tmp=*this; --*this; return tmp; }
	friend modnum operator + (const modnum& a, const modnum& b) { return modnum(a) += b; }
	friend modnum operator - (const modnum& a, const modnum& b) { return modnum(a) -= b; }
	friend modnum operator * (const modnum& a, const modnum& b) { return modnum(a) *= b; }
	friend modnum operator / (const modnum& a, const modnum& b) { return modnum(a) /= b; }
	friend ostream& operator<<(std::ostream& os, const modnum& o)
	{
		os << o.v;
		return os;
	}
	friend istream& operator>>(std::istream& is, modnum& o)
	{
		is >> o.v;
		return is;
	}
};
const ll mod=998244353,inf=1e18;
const int N=105;
using mi=modnum<mod>;
int n,m,a[N][N],b[N][N];
pii inv[N*N];
vector<tii> ans;
void output(string s=""){
	cout<<s<<endl;
	for(int i=0;i<n;i++) for(int j=0;j<m;j++) cout<<a[i][j]<<" \n"[j==m-1];
}
void rMove(int i,int r){
	r+=n*m;
	r%=m;
	if(!r) return;
	ans.push_back({1,i+1,r});
	for(int j=0;j<m;j++) b[i][(j+r)%m]=a[i][j];
	for(int j=0;j<m;j++){
		a[i][j]=b[i][j];
		inv[a[i][j]]={i,j};
	}
}
void cMove(int j,int c){
	c+=n*m;
	c%=n;
	if(!c) return;
	ans.push_back({2,j+1,c});
	for(int i=0;i<n;i++) b[(i+c)%n][j]=a[i][j];
	for(int i=0;i<n;i++){
		a[i][j]=b[i][j];
		inv[a[i][j]]={i,j};
	}
}
int main(){
	ios::sync_with_stdio(false); cin.tie(0);
	cin>>n>>m;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cin>>a[i][j];
			b[i][j]=a[i][j];
			inv[a[i][j]]={i,j};
		}
	}
	//output("Start");
	// Step 1
	for(int i=0;i<n-1;i++){
		for(int j=0;j<m-1;j++){
			auto [x,y]=inv[(n-2-i)*m+j];
			rMove(x,m-1-y);
			cMove(m-1,n-1-x);
			if(x!=n-1) rMove(x,y+1);
			rMove(n-1,j+1);
			cMove(j,1);
			//output("Step "+to_string(i)+" "+to_string(j));
		}
		//output("Step "+to_string(i));
	}
	//output("After Step 1");
	uniform_int_distribution<> gen1(0,m-1);
	uniform_int_distribution<> gen2(0,n-1);
	do{
		rMove(n-1,gen1(rng));
		cMove(m-1,gen2(rng));
		// Step 2
		for(int j=0;j<m;j++){
			auto [x,y]=inv[(n-1)*m+j];
			if(x!=n-1){
				rMove(n-1,j);
				cMove(m-1,n-1-x);
				x=n-1;
			}
			rMove(n-1,m-1-y);
			cMove(m-1,1);
			if(j) rMove(n-1,m-2-inv[(n-1)*m+j-1][1]);
			cMove(m-1,m-1);
		}
		//output("After Step 2");
		// Step 3
		for(int i=0;i<n;i++){
			int x=inv[m*i+m-1][0];
			if(!i){
				cMove(m-1,n-x);
				continue;
			}
			if(x==i) continue;
			cMove(m-1,n-1-x);
			rMove(n-1,m/2);
			int v=a[n-1][m-1];
			x=inv[m*(i-1)+m-1][0];
			cMove(m-1,n-2-x);
			rMove(n-1,m/2);
			x=inv[v][0];
			cMove(m-1,n-1-x);
			rMove(n-1,m/2);
			x=inv[m-1][0];
			cMove(m-1,n-x);
			//output(to_string(i));
		}
		//output("After Step 3");
	}while(a[n-1][0]!=(n-1)*m);
	cout<<ans.size()<<"\n";
	for(auto [x,y,z]: ans) cout<<x<<" "<<y<<" "<<z<<"\n";
	//output("Result");
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 44 ms 1720 KB Output is correct
6 Correct 51 ms 2088 KB Output is correct
7 Correct 37 ms 1612 KB Output is correct
8 Correct 51 ms 1848 KB Output is correct
9 Correct 44 ms 1652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 44 ms 1720 KB Output is correct
18 Correct 51 ms 2088 KB Output is correct
19 Correct 37 ms 1612 KB Output is correct
20 Correct 51 ms 1848 KB Output is correct
21 Correct 44 ms 1652 KB Output is correct
22 Correct 36 ms 1508 KB Output is correct
23 Correct 37 ms 1576 KB Output is correct
24 Correct 43 ms 1804 KB Output is correct
25 Correct 40 ms 1612 KB Output is correct
26 Correct 38 ms 1648 KB Output is correct
27 Correct 36 ms 1624 KB Output is correct
28 Correct 66 ms 2440 KB Output is correct
29 Correct 35 ms 1580 KB Output is correct
30 Correct 41 ms 1496 KB Output is correct
31 Correct 37 ms 1572 KB Output is correct
32 Correct 36 ms 1500 KB Output is correct
33 Incorrect 14 ms 1100 KB Contestant's solution is invalid
34 Halted 0 ms 0 KB -