結果
問題 | No.1820 NandShift |
ユーザー | PCTprobability |
提出日時 | 2022-01-21 23:14:57 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 6,602 bytes |
コンパイル時間 | 4,752 ms |
コンパイル使用メモリ | 274,340 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-05-04 14:41:23 |
合計ジャッジ時間 | 5,177 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
ソースコード
#include <bits/stdc++.h> using namespace std; #if __has_include(<atcoder/all>) #include <atcoder/all> using namespace atcoder; #endif using ll = long long; using ld = long double; using ull = unsigned long long; #define endl "\n" typedef pair<int,int> Pii; #define REP(i, n) for (int i = 0; i < (n); ++i) #define REP3(i, m, n) for (int i = (m); (i) < int(n); ++ (i)) #define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++) #define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++) #define ALL(x) begin(x), end(x) #define PB push_back #define rrep(i,a,b) for(int i=a;i>=b;i--) #define fore(i,a) for(auto &i:a) #define all(s) (s).begin(),(s).end() #define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i) #define drep(i, n) drep2(i, n, 0) #define rever(vec) reverse(vec.begin(), vec.end()) #define sor(vec) sort(vec.begin(), vec.end()) #define fi first #define se second #define pb push_back #define P pair<ll,ll> #define PQminll priority_queue<ll, vector<ll>, greater<ll>> #define PQmaxll priority_queue<ll,vector<ll>,less<ll>> #define PQminP priority_queue<P, vector<P>, greater<P>> #define PQmaxP priority_queue<P,vector<P>,less<P>> #define NP next_permutation //typedef string::const_iterator State; //class ParseError {}; //const ll mod = 1000000009; const ll mod = 998244353; //const ll mod = 1000000007; const ll inf = 4100000000000000000ll; const ld eps = ld(0.000000000001); const long double pi = 3.141592653589793; template<class T>void vcin(vector<T> &n){for(int i=0;i<int(n.size());i++) cin>>n[i];} template<class T,class K>void vcin(vector<T> &n,vector<K> &m){for(int i=0;i<int(n.size());i++) cin>>n[i]>>m[i];} template<class T>void vcout(vector<T> &n){for(int i=0;i<int(n.size());i++){cout<<n[i]<<" ";}cout<<endl;} template<class T>void vcin(vector<vector<T>> &n){for(int i=0;i<int(n.size());i++){for(int j=0;j<int(n[i].size());j++){cin>>n[i][j];}}} template<class T>void vcout(vector<vector<T>> &n){for(int i=0;i<int(n.size());i++){for(int j=0;j<int(n[i].size());j++){cout<<n[i][j]<<" ";}cout<<endl;}cout<<endl;} void yes(bool a){cout<<(a?"yes":"no")<<endl;} void YES(bool a){cout<<(a?"YES":"NO")<<endl;} void Yes(bool a){cout<<(a?"Yes":"No")<<endl;} void possible(bool a){ cout<<(a?"possible":"impossible")<<endl; } void Possible(bool a){ cout<<(a?"Possible":"Impossible")<<endl; } void POSSIBLE(bool a){ cout<<(a?"POSSIBLE":"IMPOSSIBLE")<<endl; } template<class T>void print(T a){cout<<a<<endl;} template<class T,class F>void print(pair<T,F> a){cout<<a.fi<<" "<<a.se<<endl;} template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0;} template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0;} template<class T> void ifmin(T t,T u){if(t>u){cout<<-1<<endl;}else{cout<<t<<endl;}} template<class T> void ifmax(T t,T u){if(t>u){cout<<-1<<endl;}else{cout<<t<<endl;}} ll fastgcd(ll u,ll v){ll shl=0;while(u&&v&&u!=v){bool eu=!(u&1);bool ev=!(v&1);if(eu&&ev){++shl;u>>=1;v>>=1;}else if(eu&&!ev){u>>=1;}else if(!eu&&ev){v>>=1;}else if(u>=v){u=(u-v)>>1;}else{ll tmp=u;u=(v-u)>>1;v=tmp;}}return !u?v<<shl:u<<shl;} ll modPow(ll a, ll n, ll mod) { if(mod==1) return 0;ll ret = 1; ll p = a % mod; while (n) { if (n & 1) ret = ret * p % mod; p = p * p % mod; n >>= 1; } return ret; } vector<ll> divisor(ll x){ vector<ll> ans; for(ll i = 1; i * i <= x; i++){ if(x % i == 0) {ans.push_back(i); if(i*i!=x){ ans.push_back(x / ans[i]);}}}sor(ans); return ans; } ll pop(ll x){return __builtin_popcountll(x);} ll poplong(ll x){ll y=-1;while(x){x/=2;y++;}return y;} void cincout() { ios::sync_with_stdio(false); std::cin.tie(nullptr); cout<< fixed << setprecision(10); } ll m; vector<ll> nand(vector<ll> &a,vector<ll> &b){ vector<ll> ret(m); for(int i=0;i<m;i++){ if(a[i]&&b[i]) ret[i]=0; else ret[i]=1; } return ret; } pair<vector<ll>,vector<ll>> bunkai(vector<ll> &a){ vector<ll> x(m),y(m); ll c=0; for(int i=1;i<a.size();i++) if(a[i]!=a[i-1]) c++; if(c<=2) return {{-1},{-1}}; for(int i=0;i<a.size();i++){ if(a[i]==0){ x[i]=1; y[i]=1; } } ll p=0; for(int i=0;i<a.size();i++){ if(i&&a[i]==0&&a[i-1]==1) p^=1; if(a[i]==1){ if(p) x[i]++; else y[i]++; } } return {x,y}; } ll diff(vector<ll> &a){ ll c=0; for(int i=1;i<a.size();i++) if(a[i]!=a[i-1]) c++; return c; } ll nonuse=10000000; void copy(ll p,ll q){ cout<<2<<" "<<nonuse<<" "<<p<<" "<<p<<endl; cout<<2<<" "<<q<<" "<<nonuse<<" "<<nonuse<<endl; nonuse++; } int main(){ cincout(); ll n; cin>>n>>m; string x; cin>>x; //1000 以降で作るとする vector<vector<ll>> v(10000); cout<<2<<" "<<1000<<" "<<0<<" "<<0<<endl; vector<ll> u(m,1); v[1000]=u; //{1,1,1,1,...} for(int i=1;i<m;i++){ cout<<1<<" "<<1000+i<<" "<<1000<<endl; u[i-1]=0; v[1000+i]=u; //{0,0,1,1,1,1...}(0 が i 個) } vector<ll> z(m,0); for(int i=1;i<m;i++){ z[i-1]=1; v[2000+i]=z; cout<<2<<" "<<2000+i<<" "<<1000+i<<" "<<1000+i<<endl; } vector<vector<ll>> g(10000); ll now=3000; vector<ll> y(m); for(int i=0;i<m;i++) if(x[i]-'0') y[i]=1; v[0]=y; if(diff(y)>=3){ auto f=bunkai(v[0]); v[now]=f.fi; v[now+1]=f.se; g[0].pb(now); g[0].pb(now+1); now+=2; } for(int i=3000;i<10000;i++){ if(v[i].size()&&diff(v[i])>=3){ auto f=bunkai(v[i]); v[now]=f.fi; v[now+1]=f.se; g[i].pb(now); g[i].pb(now+1); now+=2; } } for(int i=3000;i<10000;i++){ if(v[i].size()&&g[i].size()==0){ if(diff(v[i])==0){ if(v[i][0]==1){ copy(1000,i); v[i]=v[1000]; } continue; } if(diff(v[i])==1){ ll now=1; for(int j=1;j<m;j++){ if(v[i][j]!=v[i][j-1]) break; now++; } //now 回最後に 2 倍 //m-now を持ってくる copy(2000+(m-now),i); for(int j=0;j<now;j++){ cout<<1<<" "<<i<<" "<<i<<endl; } if(v[i][0]){ cout<<2<<" "<<i<<" "<<i<<" "<<i<<endl; } continue; } ll now=1; for(int j=1;j<m;j++){ if(v[i][j]!=v[i][j-1]) break; now++; } ll now2=1; for(int j=m-2;j>=0;j--){ if(v[i][j+1]!=v[i][j]) break; now2++; } copy(2000+(m-(now+now2)),i); for(int j=0;j<now;j++){ cout<<1<<" "<<i<<" "<<i<<endl; } if(v[i][0]){ cout<<2<<" "<<i<<" "<<i<<" "<<i<<endl; } } } for(int i=9999;i>=0;i--){ if(g[i].size()){ cout<<2<<" "<<i<<" "<<g[i][0]<<" "<<g[i][1]<<endl; v[i]=nand(v[g[i][0]],v[g[i][1]]); } } }