답안 #804113

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
804113 2023-08-03T07:14:31 Z moe_solution(#10139) Shifty Grid (CCO17_shifty) C++17
0 / 25
1233 ms 4892 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=2e5+5,M=66,L=60;
using mi=modnum<mod>;
int n,m;
vector<vector<int>> a;
vector<tii> ans;
void rMove(int i,int r){
	ans.push_back({1,i+1,r});
	vector<vector<int>> b=a;
	for(int j=0;j<m;j++) b[i][(j+r)%m]=a[i][j];
	a=b;
}
void cMove(int j,int c){
	ans.push_back({2,j+1,c});
	vector<vector<int>> b=a;
	for(int i=0;i<n;i++) b[(i+c)%n][j]=a[i][j];
	a=b;
}
void rSwap2(int i){
	int j=i+1;
	if(j==n) j=i-1;
	cMove(0,1);
	rMove(j,m-1);
	cMove(m-1,n-1);
	rMove(j,1);
	cMove(0,n-1);
}
void rSwap(int i,int j){
	debug(i,j);
	if(m==2){
		rMove(i,1);
		return;
	}
	rMove(i,m-1-j);
	rSwap2(i);
	rMove(i,(j+1)%m);
}
void cSwap2(int i){
	int j=i+1;
	if(j==m) j=i-1;
	rMove(0,1);
	cMove(j,n-1);
	rMove(n-1,m-1);
	cMove(j,1);
	rMove(0,m-1);
}
void cSwap(int i,int j){
	if(n==2){
		cMove(j,1);
		return;
	}
	cMove(j,n-1-i);
	cSwap2(j);
	cMove(j,(i+1)%n);
}
void movePath(int sx,int sy,int ex,int ey){
	while(sx>ex){
		cSwap(sx-1,sy);
		sx--;
	}
	if(sx<ex){
		cSwap(sx,sy);
		sx++;
	}
	while(sy>ey){
		rSwap(sx,sy-1);
		sy--;
	}
	if(sy<ey){
		rSwap(sx,sy);
		sy++;
	}
}
int main(){
	ios::sync_with_stdio(false); cin.tie(0);
	cin>>n>>m;
	a=vector<vector<int>>(n,vector<int>(m));
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cin>>a[i][j];
		}
	}
	for(int i=0;i<n;i++) for(int j=0;j<m;j++){
		int x=0,y=0;
		for(int ii=0;ii<n;ii++) for(int jj=0;jj<m;jj++){
			if(a[ii][jj]==i*m+j){
				x=ii;
				y=jj;
			}
		}
		movePath(x,y,i,j);
		debug(x,y,i,j,a);
	}
	cout<<ans.size()<<"\n";
	for(auto [x,y,z]: ans) cout<<x<<" "<<y<<" "<<z<<"\n";
	debug(a);
	return 0;
}

Compilation message

Main.cpp: In function 'void rSwap(int, int)':
Main.cpp:14:20: warning: statement has no effect [-Wunused-value]
   14 | #define debug(...) 42
      |                    ^~
Main.cpp:120:2: note: in expansion of macro 'debug'
  120 |  debug(i,j);
      |  ^~~~~
Main.cpp: In function 'int main()':
Main.cpp:14:20: warning: statement has no effect [-Wunused-value]
   14 | #define debug(...) 42
      |                    ^~
Main.cpp:183:3: note: in expansion of macro 'debug'
  183 |   debug(x,y,i,j,a);
      |   ^~~~~
Main.cpp:14:20: warning: statement has no effect [-Wunused-value]
   14 | #define debug(...) 42
      |                    ^~
Main.cpp:187:2: note: in expansion of macro 'debug'
  187 |  debug(a);
      |  ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 1 ms 212 KB Output is correct
5 Incorrect 0 ms 212 KB Contestant's solution is invalid
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 18 ms 352 KB Output is correct
6 Incorrect 1233 ms 4892 KB Integer parameter [name=K] equals to 221424, violates the range [0, 100000]
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 1 ms 212 KB Output is correct
5 Incorrect 0 ms 212 KB Contestant's solution is invalid
6 Halted 0 ms 0 KB -