# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
804134 |
2023-08-03T07:18:31 Z |
moe_solution(#10139) |
Shifty Grid (CCO17_shifty) |
C++17 |
|
1210 ms |
4240 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){
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(sy>ey){
rSwap(sx,sy-1);
sy--;
}
if(sy<ey){
rSwap(sx,sy);
sy++;
}
while(sx>ex){
cSwap(sx-1,sy);
sx--;
}
if(sx<ex){
cSwap(sx,sy);
sx++;
}
}
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 'int main()':
Main.cpp:14:20: warning: statement has no effect [-Wunused-value]
14 | #define debug(...) 42
| ^~
Main.cpp:182:3: note: in expansion of macro 'debug'
182 | debug(x,y,i,j,a);
| ^~~~~
Main.cpp:14:20: warning: statement has no effect [-Wunused-value]
14 | #define debug(...) 42
| ^~
Main.cpp:186:2: note: in expansion of macro 'debug'
186 | debug(a);
| ^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
232 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 |
18 ms |
368 KB |
Output is correct |
6 |
Incorrect |
1210 ms |
4240 KB |
Integer parameter [name=K] equals to 195314, violates the range [0, 100000] |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
232 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 |
18 ms |
368 KB |
Output is correct |
18 |
Incorrect |
1210 ms |
4240 KB |
Integer parameter [name=K] equals to 195314, violates the range [0, 100000] |
19 |
Halted |
0 ms |
0 KB |
- |