結果
問題 | No.2263 Perms |
ユーザー | kariya1975 |
提出日時 | 2023-04-15 02:36:45 |
言語 | JavaScript (node v21.7.1) |
結果 |
TLE
|
実行時間 | - |
コード長 | 11,453 bytes |
コンパイル時間 | 195 ms |
コンパイル使用メモリ | 6,948 KB |
実行使用メモリ | 57,072 KB |
最終ジャッジ日時 | 2024-10-10 17:06:32 |
合計ジャッジ時間 | 4,421 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 101 ms
51,056 KB |
testcase_01 | AC | 68 ms
39,424 KB |
testcase_02 | AC | 68 ms
39,424 KB |
testcase_03 | AC | 68 ms
39,680 KB |
testcase_04 | AC | 68 ms
39,296 KB |
testcase_05 | TLE | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
testcase_40 | -- | - |
ソースコード
/// source code (in typescript) // // @kariay1975/atcoder-tslib is a private package: // import { // Input, // InputStdin, // sortAsNumber, // sumNumber, // } from '@kariya1975/atcoder-tslib'; // // use babel-plugin-macros for speed. // import { // range, // arrayWith, // } from '@kariya1975/atcoder-tslib/macro'; // // // type int = number; // // const nextPerm = (xs: int[]): boolean => { // const swap = (i: int, j: int): void => { // const t = xs[i]; // xs[i] = xs[j]; // xs[j] = t; // }; // for (const i of range(xs.length - 2, -1, -1)) { // if (xs[i] >= xs[i + 1]) continue; // for (const j of range(xs.length -1, -1, -1)) { // if (xs[j] <= xs[i]) continue; // swap(i, j); // for (const k of range(xs.length - i - 1)) { // const l = i + 1 + k; // const m = xs.length - 1 - k; // if (l > m) break; // swap(l, m); // } // break; // } // return true; // } // return false; // }; // // const main = (input: Input, output: any[]): void => { // const [N, M] = input.getInts(2); // const A: int[][] = []; // for (const _ of range(N)) { // const a = input.getInts(N); // if (sumNumber(a) !== M) { // output.push(-1); // return; // } // A.push(a); // } // // const dfs = (i: int, perms: int[][]): int[][] | false => { // // console.error(i, perms) // if (i === N) return perms; // const cs: int[] = []; // for (const j of range(N)) { // for (const _ of range(A[i][j])) cs.push(j); // } // do { // let ps: int[][] = []; // for (const p of perms) ps.push([...p]); // let ok = true; // for (const i of range(M)) { // if (ps[i].includes(cs[i])) { // ok = false; // break; // } // ps[i].push(cs[i]); // } // if (!ok) continue; // const result = dfs(i + 1, ps); // if (result !== false) return result; // } while (nextPerm(cs)); // return false; // }; // // const result = dfs(0, arrayWith(M, () => [])); // if (result === false) { // output.push(-1); // } else { // for (const p of result) { // output.push(p.map(x => x + 1).join(' ')); // } // } // }; // // const input = new InputStdin(); // input.setup().then(_ => { // const output = []; // main(input, output); // console.log(output.join('n')); // }); // /// The code above transpiles as follows: var F=Object.create;var z=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var W=Object.getPrototypeOf,C=Object.prototype.hasOwnProperty;var R=t=>z(t,"__esModule",{value:!0});var q=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var L=(t,e,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of O(e))!C.call(t,i)&&i!=="default"&&z(t,i,{get:()=>e[i],enumerable:!(r=k(e,i))||r.enumerable});return t},w=t=>L(R(z(t!=null?F(W(t)):{},"default",t&&t.__esModule&&"default"in t?{get:()=>t.default,enumerable:!0}:{value:t,enumerable:!0})),t);var S=q((nt,I)=>{"use strict";var Q=function(t,e){return t<e};function u(t){if(!(this instanceof u))return new u(t);this.array=[],this.size=0,this.compare=t||Q}u.prototype.clone=function(){var t=new u(this.compare);return t.size=this.size,t.array=this.array.slice(0,this.size),t};u.prototype.add=function(t){var e=this.size;this.array[this.size]=t,this.size+=1;for(var r,i;e>0&&(r=e-1>>1,i=this.array[r],!!this.compare(t,i));)this.array[e]=i,e=r;this.array[e]=t};u.prototype.heapify=function(t){this.array=t,this.size=t.length;var e;for(e=this.size>>1;e>=0;e--)this._percolateDown(e)};u.prototype._percolateUp=function(t,e){for(var r=this.array[t],i,s;t>0&&(i=t-1>>1,s=this.array[i],!(!e&&!this.compare(r,s)));)this.array[t]=s,t=i;this.array[t]=r};u.prototype._percolateDown=function(t){for(var e=this.size,r=this.size>>>1,i=this.array[t],s,n,o;t<r&&(s=(t<<1)+1,n=s+1,o=this.array[s],n<e&&this.compare(this.array[n],o)&&(s=n,o=this.array[n]),!!this.compare(o,i));)this.array[t]=o,t=s;this.array[t]=i};u.prototype._removeAt=function(t){if(!(t>this.size-1||t<0))return this._percolateUp(t,!0),this.poll()};u.prototype.remove=function(t){for(var e=0;e<this.size;e++)if(!this.compare(this.array[e],t)&&!this.compare(t,this.array[e]))return this._removeAt(e),!0;return!1};u.prototype.removeOne=function(t){if(typeof t=="function"){for(var e=0;e<this.size;e++)if(t(this.array[e]))return this._removeAt(e)}};u.prototype.removeMany=function(t,e){if(typeof t!="function"||this.size<1)return[];e=e?Math.min(e,this.size):this.size;for(var r=0,i=new Array(e),s=0,n=new Array(this.size);r<e&&!this.isEmpty();){var o=this.poll();t(o)?i[r++]=o:n[s++]=o}i.length=r;for(var h=0;h<s;)this.add(n[h++]);return i};u.prototype.peek=function(){if(this.size!=0)return this.array[0]};u.prototype.poll=function(){if(this.size!=0){var t=this.array[0];return this.size>1?(this.array[0]=this.array[--this.size],this._percolateDown(0)):this.size-=1,t}};u.prototype.replaceTop=function(t){if(this.size!=0){var e=this.array[0];return this.array[0]=t,this._percolateDown(0),e}};u.prototype.trim=function(){this.array=this.array.slice(0,this.size)};u.prototype.isEmpty=function(){return this.size===0};u.prototype.forEach=function(t){if(!(this.isEmpty()||typeof t!="function"))for(var e=0,r=this.clone();!r.isEmpty();)t(r.poll(),e++)};u.prototype.kSmallest=function(t){if(this.size==0)return[];t=Math.min(this.size,t);var e=new u(this.compare);let r=Math.min((t>0?Math.pow(2,t-1):0)+1,this.size);e.size=r,e.array=this.array.slice(0,r);for(var i=new Array(t),s=0;s<t;s++)i[s]=e.poll();return i};I.exports=u});var A=q((zt,T)=>{"use strict";function a(t){if(this._capacity=N(t),this._length=0,this._front=0,E(t)){for(var e=t.length,r=0;r<e;++r)this[r]=t[r];this._length=e}}a.prototype.toArray=function(){for(var e=this._length,r=new Array(e),i=this._front,s=this._capacity,n=0;n<e;++n)r[n]=this[i+n&s-1];return r};a.prototype.push=function(e){var r=arguments.length,i=this._length;if(r>1){var s=this._capacity;if(i+r>s){for(var o=0;o<r;++o){this._checkCapacity(i+1);var n=this._front+i&this._capacity-1;this[n]=arguments[o],i++,this._length=i}return i}else{for(var n=this._front,o=0;o<r;++o)this[n+i&s-1]=arguments[o],n++;return this._length=i+r,i+r}}if(r===0)return i;this._checkCapacity(i+1);var o=this._front+i&this._capacity-1;return this[o]=e,this._length=i+1,i+1};a.prototype.pop=function(){var e=this._length;if(e!==0){var r=this._front+e-1&this._capacity-1,i=this[r];return this[r]=void 0,this._length=e-1,i}};a.prototype.shift=function(){var e=this._length;if(e!==0){var r=this._front,i=this[r];return this[r]=void 0,this._front=r+1&this._capacity-1,this._length=e-1,i}};a.prototype.unshift=function(e){var r=this._length,i=arguments.length;if(i>1){var o=this._capacity;if(r+i>o){for(var h=i-1;h>=0;h--){this._checkCapacity(r+1);var o=this._capacity,s=(this._front-1&o-1^o)-o;this[s]=arguments[h],r++,this._length=r,this._front=s}return r}else{for(var n=this._front,h=i-1;h>=0;h--){var s=(n-1&o-1^o)-o;this[s]=arguments[h],n=s}return this._front=n,this._length=r+i,r+i}}if(i===0)return r;this._checkCapacity(r+1);var o=this._capacity,h=(this._front-1&o-1^o)-o;return this[h]=e,this._length=r+1,this._front=h,r+1};a.prototype.peekBack=function(){var e=this._length;if(e!==0){var r=this._front+e-1&this._capacity-1;return this[r]}};a.prototype.peekFront=function(){if(this._length!==0)return this[this._front]};a.prototype.get=function(e){var r=e;if(r===(r|0)){var i=this._length;if(r<0&&(r=r+i),!(r<0||r>=i))return this[this._front+r&this._capacity-1]}};a.prototype.isEmpty=function(){return this._length===0};a.prototype.clear=function(){for(var e=this._length,r=this._front,i=this._capacity,s=0;s<e;++s)this[r+s&i-1]=void 0;this._length=0,this._front=0};a.prototype.toString=function(){return this.toArray().toString()};a.prototype.valueOf=a.prototype.toString;a.prototype.removeFront=a.prototype.shift;a.prototype.removeBack=a.prototype.pop;a.prototype.insertFront=a.prototype.unshift;a.prototype.insertBack=a.prototype.push;a.prototype.enqueue=a.prototype.push;a.prototype.dequeue=a.prototype.shift;a.prototype.toJSON=a.prototype.toArray;Object.defineProperty(a.prototype,"length",{get:function(){return this._length},set:function(){throw new RangeError("")}});a.prototype._checkCapacity=function(e){this._capacity<e&&this._resizeTo(N(this._capacity*1.5+16))};a.prototype._resizeTo=function(e){var r=this._capacity;this._capacity=e;var i=this._front,s=this._length;if(i+s>r){var n=i+s&r-1;H(this,0,this,r,n)}};var E=Array.isArray;function H(t,e,r,i,s){for(var n=0;n<s;++n)r[n+i]=t[n+e],t[n+e]=void 0}function J(t){return t=t>>>0,t=t-1,t=t|t>>1,t=t|t>>2,t=t|t>>4,t=t|t>>8,t=t|t>>16,t+1}function N(t){if(typeof t!="number")if(E(t))t=t.length;else return 16;return J(Math.min(Math.max(16,t),1073741824))}T.exports=a});var _=w(require("fs"));var b=class{constructor(e){this.data=e!=null?e:"",this.index=0}isSpace(e){return e===" "||e===` `}getString(){for(;this.index<this.data.length&&this.isSpace(this.data[this.index]);)this.index++;let e=this.index;for(;this.index<this.data.length&&!this.isSpace(this.data[this.index]);)this.index++;let r=this.index;return this.data.slice(e,r)}getBigInt(){return BigInt(this.getString())}getInt(){return parseInt(this.getString())}getNumber(){return Number(this.getString())}getNumbers(e){let r=[];for(let i of d(e))r.push(this.getNumber());return r}getBigInts(e){let r=[];for(let i of d(e))r.push(this.getBigInt());return r}getInts(e){let r=[];for(let i of d(e))r.push(this.getInt());return r}getStrings(e){let r=[];for(let i of d(e))r.push(this.getString());return r}get(e){if(typeof e=="number")return this.getNumber();if(typeof e=="bigint")return this.getBigInt();if(typeof e=="string")return this.getString()}gets(e,r){if(typeof e=="number")return this.getNumbers(r);if(typeof e=="bigint")return this.getBigInts(r);if(typeof e=="string")return this.getStrings(r)}},v=class extends b{constructor(){super();(0,_.existsSync)("/dev/stdin")&&(super.data=(0,_.readFileSync)("/dev/stdin","utf-8"))}async setup(){if((0,_.existsSync)("/dev/stdin"))return;let e=[];for await(let s of process.stdin)e.push(s);let i=Buffer.concat(e).toString();super.data=i}};var j=w(S());var V=w(A());var m=(t,e)=>{let r=new Array(t);for(let i=0;i<t;++i)r[i]=e(i);return r};function*Z(t){for(let e=0;e<t;++e)yield e}function*B(t,e,r=1){if(r>0)for(let i=t;i<e;i+=r)yield i;else if(r<0)for(let i=t;i>e;i+=r)yield i}var d=(t,e=null,r=null)=>e===null?Z(t):r===null?B(t,e):B(t,e,r);var x=t=>{let e=0;for(let r of t)e+=r;return e};var tt=t=>{let e=(r,i)=>{let s=t[r];t[r]=t[i],t[i]=s};for(let r=t.length-2,i=-1,s=-1;r>i;r+=s)if(!(t[r]>=t[r+1])){for(let n=t.length-1,o=-1,h=-1;n>o;n+=h)if(!(t[n]<=t[r])){e(r,n);for(let p=0,l=t.length-r-1;p<l;++p){let f=r+1+p,g=t.length-1-p;if(f>g)break;e(f,g)}break}return!0}return!1},et=(t,e)=>{let[r,i]=t.getInts(2),s=[];for(let h=0,p=r;h<p;++h){let l=t.getInts(r);if(x(l)!==i){e.push(-1);return}s.push(l)}let n=(h,p)=>{if(h===r)return p;let l=[];for(let f=0,g=r;f<g;++f)for(let y=0,c=s[h][f];y<c;++y)l.push(f);do{let f=[];for(let c of p)f.push([...c]);let g=!0;for(let c=0,$=i;c<$;++c){if(f[c].includes(l[c])){g=!1;break}f[c].push(l[c])}if(!g)continue;let y=n(h+1,f);if(y!==!1)return y}while(tt(l));return!1},o=n(0,m(i,()=>[]));if(o===!1)e.push(-1);else for(let h of o)e.push(h.map(p=>p+1).join(" "))},D=new v;D.setup().then(t=>{let e=[];et(D,e),console.log(e.join(` `))});