結果
| 問題 |
No.585 工夫のないパズル
|
| コンテスト | |
| ユーザー |
nmnmnmnmnmnmnm
|
| 提出日時 | 2017-09-11 00:39:23 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 2,802 bytes |
| コンパイル時間 | 963 ms |
| コンパイル使用メモリ | 99,352 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-22 02:44:08 |
| 合計ジャッジ時間 | 1,579 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 12 |
コンパイルメッセージ
main.cpp: In function ‘void move(std::string&, char, ll, ll)’:
main.cpp:91:7: warning: ‘c3’ may be used uninitialized in this function [-Wmaybe-uninitialized]
91 | rotR(s,N-1,c3-c2);
| ~~~~^~~~~~~~~~~~~
main.cpp:92:7: warning: ‘c2’ may be used uninitialized in this function [-Wmaybe-uninitialized]
92 | rotC(s,c2,r2-(N-1));
| ~~~~^~~~~~~~~~~~~~~
main.cpp:92:7: warning: ‘r2’ may be used uninitialized in this function [-Wmaybe-uninitialized]
main.cpp: In function ‘void toLeft(std::string&, char)’:
main.cpp:114:7: warning: ‘c’ may be used uninitialized in this function [-Wmaybe-uninitialized]
114 | rotC(s,c,1);
| ~~~~^~~~~~~
main.cpp:113:7: warning: ‘r’ may be used uninitialized in this function [-Wmaybe-uninitialized]
113 | rotR(s,r,-2);
| ~~~~^~~~~~~~
main.cpp: In function ‘int main()’:
main.cpp:139:7: warning: ‘c’ may be used uninitialized in this function [-Wmaybe-uninitialized]
139 | rotR(s,N-1,-c);
| ~~~~^~~~~~~~~~
ソースコード
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
#define MOD 1000000007
#define N 4
string A = "ABCDEFGHIJKLMNOP";
vector<pair<string,pair<ll,ll> > > ans;
// 指定した行rを右にa個だけRotate (-N<=a<=N)
void rotR(string &s, ll r, ll a){
a *= -1;
a += N;
a %= N;
if(a==1)ans.pb(mp("R",mp(r,3)));
if(a==2)ans.pb(mp("R",mp(r,2)));
if(a==3)ans.pb(mp("R",mp(r,1)));
rep(i,0,a){
rep(j,0,N-1){
swap(s[r*N+j],s[r*N+j+1]);
}
}
}
// 指定した列cの下にa個だけRotate (-N<=a<=N)
void rotC(string &s, ll c, ll a){
a *= -1;
a += N;
a %= N;
if(a==1)ans.pb(mp("C",mp(c,3)));
if(a==2)ans.pb(mp("C",mp(c,2)));
if(a==3)ans.pb(mp("C",mp(c,1)));
rep(i,0,a){
rep(j,0,N-1){
swap(s[j*N+c],s[(j+1)*N+c]);
}
}
}
// 最下段の整合性を無視することである文字を指定位置へ移動。
void move(string &s, char ch, ll r1, ll c1){
ll r2,c2;
rep(i,0,N*N){
if(s[i]==ch){
r2 = i/N;
c2 = i%N;
}
}
ll c3;
rep(i,0,N){
if(i!=c1&&i!=c2){
c3 = i;
break;
}
}
rotC(s,c2,(N-1)-r2);
rotR(s,N-1,c3-c2);
rotC(s,c2,r2-(N-1));
rotC(s,c1,(N-1)-r1);
rotR(s,N-1,c1-c3);
rotC(s,c1,r1-(N-1));
}
// 指定した文字を1つ左へ (右の文字と入れ替え) N=4に限る
void toLeft(string &s, char ch){
ll r,c;
rep(i,0,N*N){
if(s[i]==ch){
r = i/N;
c = i%N;
}
}
rotR(s,r,-1);
rotC(s,c,-1);
rotR(s,r,-1);
rotC(s,c,1);
rotR(s,r,-1);
rotC(s,c,-1);
rotR(s,r,-2);
rotC(s,c,1);
}
int main() {
string s;
rep(i,0,4){
string s1;
cin>>s1;
s += s1;
}
string s2 = s;
sort(all(s2));
if(s2!=A){
cout << -1 << endl;
return 0;
}
rep(i,0,N*(N-1)){
move(s,A[i],i/N,i%N);
}
ll c;
rep(i,0,N*N){
if(s[i]==A[N*(N-1)]){
c = i%N;
}
}
rotR(s,N-1,-c);
rep(i,1,N){
char ch = A[N*(N-1)+i];
per(j,i+1,N){
if(s[N*(N-1)+j]==ch){
toLeft(s,ch);
}
}
}
cout << ans.sz << endl;
rep(i,0,ans.sz){
cout << ans[i].fi << " " << ans[i].se.fi << " " << ans[i].se.se << endl;
}
return 0;
}
nmnmnmnmnmnmnm