結果

問題 No.2597 Yet Another Topological Problem
ユーザー 👑 hos.lyrichos.lyric
提出日時 2023-12-25 01:32:07
言語 D
(dmd 2.106.1)
結果
RE  
実行時間 -
コード長 2,792 bytes
コンパイル時間 866 ms
コンパイル使用メモリ 114,944 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-12-25 01:32:16
合計ジャッジ時間 8,289 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 AC 1 ms
6,676 KB
testcase_06 RE -
testcase_07 AC 1 ms
6,676 KB
testcase_08 RE -
testcase_09 AC 1 ms
6,676 KB
testcase_10 RE -
testcase_11 AC 1 ms
6,676 KB
testcase_12 AC 1 ms
6,676 KB
testcase_13 RE -
testcase_14 AC 1 ms
6,676 KB
testcase_15 RE -
testcase_16 AC 1 ms
6,676 KB
testcase_17 AC 1 ms
6,676 KB
testcase_18 RE -
testcase_19 AC 1 ms
6,676 KB
testcase_20 RE -
testcase_21 AC 1 ms
6,676 KB
testcase_22 AC 2 ms
6,676 KB
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 AC 1 ms
6,676 KB
testcase_34 AC 1 ms
6,676 KB
testcase_35 RE -
testcase_36 RE -
testcase_37 AC 1 ms
6,676 KB
testcase_38 AC 1 ms
6,676 KB
testcase_39 AC 1 ms
6,676 KB
testcase_40 AC 1 ms
6,676 KB
testcase_41 RE -
testcase_42 AC 2 ms
6,676 KB
testcase_43 AC 1 ms
6,676 KB
testcase_44 AC 2 ms
6,676 KB
testcase_45 AC 1 ms
6,676 KB
testcase_46 AC 1 ms
6,676 KB
testcase_47 AC 1 ms
6,676 KB
testcase_48 AC 1 ms
6,676 KB
testcase_49 AC 1 ms
6,676 KB
testcase_50 AC 1 ms
6,676 KB
testcase_51 AC 1 ms
6,676 KB
testcase_52 AC 1 ms
6,676 KB
testcase_53 AC 1 ms
6,676 KB
testcase_54 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }

string COLOR(string s = "") { return "\x1b[" ~ s ~ "m"; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }




void main() {
  try {
    for (; ; ) {
      const P = readInt;
      const Q = readInt;
      
      if (Q < 2 * P) {
        // (1/2, 1)
        writeln("Possible");
        writeln("6");
        writeln("0 0");
        writeln("0 -1");
        writeln("1 -1");
        writeln("1 0");
        writeln("1 1");
        writeln("2 1");
        writeln("2 0");
      } else if (Q < 3 * P && 2 * P < Q) {
        // (1/3, 1/2)
        /*
          a = (1-R)/2
          b = R/2
          c = (1-R)/4
          d = (1+R)/4
        */
        const a = 2 * (Q-P);
        const b = 2 * P;
        const c = (Q-P);
        const d = (Q+P);
        debug {
          writefln("%s/%s %s", P, Q, [a, b, c, d]);
        }
        string s;
        s ~= "UU";
        s ~= 'R'.repeat(a).array;
        s ~= "DDD";
        s ~= 'R'.repeat(b).array;
        s ~= "UU";
        s ~= 'R'.repeat(c).array;
        s ~= "DDD";
        s ~= 'R'.repeat(d).array;
        s ~= "UU";
        alias Pt = Tuple!(int, "x", int, "y");
        Pt[] ps;
        {
          Pt p = Pt(0, 0);
          ps ~= p;
          foreach (dir; s) {
            final switch (dir) {
              case 'R': ++p.x; break;
              case 'L': ++p.x; break;
              case 'U': ++p.y; break;
              case 'D': --p.y; break;
            }
            ps ~= p;
          }
        }
        
        writeln("Possible");
        writeln(ps.length - 1);
        foreach (p; ps) {
          writeln(p.x, " ", p.y);
        }
      } else {
        writeln("Impossible");
assert(false);
      }
    }
  } catch (EOFException e) {
  }
}
0