結果
問題 | No.928 軽減税率? |
ユーザー |
![]() |
提出日時 | 2019-11-22 23:08:00 |
言語 | D (dmd 2.109.1) |
結果 |
AC
|
実行時間 | 6 ms / 1,000 ms |
コード長 | 2,150 bytes |
コンパイル時間 | 913 ms |
コンパイル使用メモリ | 138,056 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-22 03:06:10 |
合計ジャッジ時間 | 1,959 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 34 |
ソースコード
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;import std.math, std.random, std.bigint, std.datetime, std.format;void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0;string rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }T rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;T[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;T[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //void solve(){long p = rlong, q = rlong, a = rlong;long ans;if(p > q){foreach(x; 1 .. 1_000_000_001){if(x * (p - q) >= 100 * a) break;if((100 + p) * x / 100 < ((100 + q) * x + 100 * a) / 100) ans += 1;}}else if(p == q){if(a > 0) ans = 1_000_000_000;else ans = 0;}else{ans = 1_000_000_000;foreach(x; 1 .. 1_000_000_001){if(x * (q - p) >= 100 - 100 * a) break;if((100 + p) * x / 100 >= ((100 + q) * x + 100 * a) / 100) ans -= 1;}}ans.writeln;}/*floor((1 + p / 100) x) < floor((1 + q / 100) x + a)をみたす x を求める。p > q の場合:必要条件として(1 + p / 100) x < (1 + q / 100) x + a(100 + p) x < (100 + q) x + 100 a(p - q) x < 100 ax < 100 a / (p - q)この範囲を全検査すればよいp < q の場合:みたさない x を求める。floor((1 + p / 100) x) >= floor((1 + q / 100) x + a)ただし、ここで (1 + p / 100) x < (1 + q / 100) x + a なので、上記は floor((1 + p / 100) x) = floor((1 + q / 100) x + a)必要条件として(1 + q / 100) x + a < (1 + p / 100) x + 1(100 + q) x < (100 + p) x + 100 - 100 a(q - p) x < 100 - 100 aこの範囲を全検査すれば良い*/