結果

問題 No.2263 Perms
ユーザー kariya1975kariya1975
提出日時 2023-04-15 02:33:57
言語 JavaScript
(node v21.7.1)
結果
TLE  
実行時間 -
コード長 11,242 bytes
コンパイル時間 44 ms
コンパイル使用メモリ 5,248 KB
実行使用メモリ 55,824 KB
最終ジャッジ日時 2024-04-18 23:30:55
合計ジャッジ時間 4,592 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
50,544 KB
testcase_01 AC 59 ms
39,040 KB
testcase_02 AC 58 ms
39,040 KB
testcase_03 AC 59 ms
39,040 KB
testcase_04 TLE -
testcase_05 -- -
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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

/// source code (in typescript)

// // @kariay1975/atcoder-tslib is a private package: 
// import {
//   Input,
//   InputStdin,
//   sortAsNumber,
// } 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)) {
//     A.push(input.getInts(N));
//   }
// 
//   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 $=Object.create;var z=Object.defineProperty;var F=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var O=Object.getPrototypeOf,W=Object.prototype.hasOwnProperty;var C=t=>z(t,"__esModule",{value:!0});var x=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var R=(t,e,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of k(e))!W.call(t,i)&&i!=="default"&&z(t,i,{get:()=>e[i],enumerable:!(r=F(e,i))||r.enumerable});return t},w=t=>R(C(z(t!=null?$(O(t)):{},"default",t&&t.__esModule&&"default"in t?{get:()=>t.default,enumerable:!0}:{value:t,enumerable:!0})),t);var I=x((st,q)=>{"use strict";var L=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||L}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};q.exports=u});var N=x((vt,T)=>{"use strict";function a(t){if(this._capacity=E(t),this._length=0,this._front=0,M(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(E(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;X(this,0,this,r,n)}};var M=Array.isArray;function X(t,e,r,i,s){for(var n=0;n<s;++n)r[n+i]=t[n+e],t[n+e]=void 0}function H(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 E(t){if(typeof t!="number")if(M(t))t=t.length;else return 16;return H(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 l(e))r.push(this.getNumber());return r}getBigInts(e){let r=[];for(let i of l(e))r.push(this.getBigInt());return r}getInts(e){let r=[];for(let i of l(e))r.push(this.getInt());return r}getStrings(e){let r=[];for(let i of l(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 Q=w(I());var J=w(N());var d=(t,e)=>{let r=new Array(t);for(let i=0;i<t;++i)r[i]=e(i);return r};function*Y(t){for(let e=0;e<t;++e)yield e}function*A(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 l=(t,e=null,r=null)=>e===null?Y(t):r===null?A(t,e):A(t,e,r);var Z=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,g=t.length-r-1;p<g;++p){let f=r+1+p,m=t.length-1-p;if(f>m)break;e(f,m)}break}return!0}return!1},tt=(t,e)=>{let[r,i]=t.getInts(2),s=[];for(let h=0,p=r;h<p;++h)s.push(t.getInts(r));let n=(h,p)=>{if(h===r)return p;let g=[];for(let f=0,m=r;f<m;++f)for(let y=0,c=s[h][f];y<c;++y)g.push(f);do{let f=[];for(let c of p)f.push([...c]);let m=!0;for(let c=0,D=i;c<D;++c){if(f[c].includes(g[c])){m=!1;break}f[c].push(g[c])}if(!m)continue;let y=n(h+1,f);if(y!==!1)return y}while(Z(g));return!1},o=n(0,d(i,()=>[]));if(o===!1)e.push(-1);else for(let h of o)e.push(h.map(p=>p+1).join(" "))},B=new v;B.setup().then(t=>{let e=[];tt(B,e),console.log(e.join(`
`))});

0