Submission #00228
ソースコード
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 | import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.lang.reflect.Array; import java.math.BigDecimal; import java.math.BigInteger; import java.util.*; class Main { private static final PrintWriter out = new PrintWriter(System.out); private static final Scanner scanner = new Scanner(System.in); private static int dx[] = {1, 0, -1, 0, 1, 1, -1, -1}; private static int dy[] = {0, 1, 0, -1, 1, -1, 1, -1}; private static int INF = 1 << 29; private static int MOD = 1000000007; public static void main(String[] args) { // From IntelliJ IDEA int W = fgetInt(); int H = fgetInt(); int N = fgetInt(); int prevX = fgetInt(); int prevY = fgetInt(); long ans = divide( fact( prevX+prevY ) , multiply( fact(prevX), fact(prevY) )); for ( int i = 1; i < N; i++ ) { int x = fgetInt(); int y = fgetInt(); ans = ( ans * divide( fact( (x+y)-(prevX+prevY) ) , multiply( fact(x-prevX), fact(y-prevY) ) ) ) % MOD; prevX = x; prevY = y; } W--; H--; ans = ( ans * divide( fact( (W+H)-(prevX+prevY) ) , multiply( fact(W-prevX), fact(H-prevY) ) ) ) % MOD; println(ans); suomi(); } private static long fact ( int n ) { long ans = 1; for ( int i = 1; i <= n; i++ ) { ans = ( ans * i ) % MOD; } return ans; } private static long multiply ( long a, long b ) { return ( ( a % MOD) * ( b % MOD ) ) % MOD; } private static long divide ( long a, long b ) { return multiply( a, pow ( b, MOD-2 ) ); } private static boolean isMovable( int x, int y, int w, int h ) { return ( x >= 0 && y >= 0 && x < w && y < h ); } private static String fgetStr(){ return FastScanner.next(); } private static String fgetLine(){ return FastScanner.nextLine(); } private static char fgetChar(){ return fgetStr().charAt(0); } private static int fgetInt(){ return FastScanner.nextInt(); } private static long fgetLong(){ return FastScanner.nextLong(); } private static double fgetDouble(){ return FastScanner.nextDouble(); } private static BigInteger fgetBig(){ return new BigInteger(fgetStr()); } private static String reverseStr(String str){ return new StringBuffer(str).reverse().toString(); } private static void println(Object a){ out.println(a); } private static void print(Object a){ out.print(a); } private static void printf (String string, Object... args) { out. printf (string, args); } private static void suomi(){ out.flush(); } private static long pow ( long x, long n ) { final long MOD = 1000000007; long ans = 1; while ( n > 0 ) { if ( ( n & 1 ) == 1 ) { ans = (ans * x) % MOD; } x = ( x * x ) % MOD; n >>= 1; } return ans; } private static long gcd( long x, long y) { return x % y == 0 ? y : gcd(y, x % y); } private static long lcm( long x, long y) { return ( x / gcd(x, y) * y); } } class FastScanner { private static final InputStream in = System.in; private static final byte[] buffer = new byte[1024]; private static int ptr = 0; private static int buflen = 0; private static boolean hasNextByte() { if (ptr < buflen) { return true ; } else { ptr = 0; try { buflen = in.read(buffer); } catch ( IOException e) { e.printStackTrace(); } if (buflen <= 0) { return false ; } } return true ; } private static int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1; } private static boolean isPrintableChar( int c) { return 33 <= c && c <= 126; } private static boolean hasNext() { while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte(); } static String next() { if (!hasNext()) throw new NoSuchElementException(); StringBuilder sb = new StringBuilder(); int b = readByte(); while (isPrintableChar(b)) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } static String nextLine() { if (!hasNext()) throw new NoSuchElementException(); StringBuilder sb = new StringBuilder(); int b = readByte(); while (isPrintableChar(b) || b == 32) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } static long nextLong() { if (!hasNext()) throw new NoSuchElementException(); long n = 0; boolean minus = false ; int b = readByte(); if (b == '-' ) { minus = true ; b = readByte(); } if (b < '0' || '9' < b) { throw new NumberFormatException(); } while ( true ){ if ( '0' <= b && b <= '9' ) { n *= 10; n += b - '0' ; } else if (b == -1 || !isPrintableChar(b)){ return minus ? -n : n; } else { throw new NumberFormatException(); } b = readByte(); } } static int nextInt() { long nl = nextLong(); if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException(); return ( int ) nl; } static double nextDouble() { return Double.parseDouble(next()); } } |
ステータス
項目 | データ |
---|---|
問題 | 0006 - 寄り道 |
ユーザー名 | r1825 |
投稿日時 | 2018-11-24 15:38:40 |
言語 | Java |
状態 | Accepted |
得点 | 400 |
ソースコード長 | 6067 Byte |
最大実行時間 | 190 ms |
最大メモリ使用量 | 17532 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 400 / 400 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
input01.in | AC | 130 ms | 15072 KB |
1
|
input02.in | AC | 122 ms | 15508 KB |
1
|
input03.in | AC | 123 ms | 15540 KB |
1
|
input04.in | AC | 127 ms | 15652 KB |
1
|
input05.in | AC | 120 ms | 15136 KB |
1
|
input06.in | AC | 136 ms | 15480 KB |
1
|
input07.in | AC | 123 ms | 15348 KB |
1
|
input08.in | AC | 123 ms | 15232 KB |
1
|
input09.in | AC | 138 ms | 15700 KB |
1
|
input10.in | AC | 132 ms | 15224 KB |
1
|
input11.in | AC | 144 ms | 15316 KB |
1
|
input12.in | AC | 161 ms | 15292 KB |
1
|
input13.in | AC | 143 ms | 15340 KB |
1
|
input14.in | AC | 155 ms | 15488 KB |
1
|
input15.in | AC | 177 ms | 15200 KB |
1
|
input16.in | AC | 167 ms | 15340 KB |
1
|
input17.in | AC | 176 ms | 15516 KB |
1
|
input18.in | AC | 184 ms | 17532 KB |
1
|
input19.in | AC | 181 ms | 15472 KB |
1
|
input20.in | AC | 190 ms | 15408 KB |
1
|
sample.in | AC | 127 ms | 17224 KB |
1
|