結果
問題 | No.378 名声値を稼ごう |
ユーザー | vjudge1 |
提出日時 | 2024-10-12 22:42:51 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 2,396 bytes |
コンパイル時間 | 2,032 ms |
コンパイル使用メモリ | 174,268 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-12 22:42:54 |
合計ジャッジ時間 | 2,723 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 2 ms
5,248 KB |
testcase_04 | AC | 2 ms
5,248 KB |
testcase_05 | AC | 2 ms
5,248 KB |
ソースコード
# include <bits/stdc++.h> using namespace std; typedef long long ll; //# define int long long # define lc u << 1 # define rc u << 1 | 1 # define fi first # define se second const int N = 1000005; char s[N]; vector <int> add (vector <int> a, vector <int> b) { int la = a.size (), lb = b.size (); if (la < lb) return add (b, a); reverse (a.begin (), a.end ()); reverse (b.begin (), b.end ()); vector <int> c; int t = 0; for (int i = 0; i < la; i ++ ) { t += a[i]; if (i < lb) t += b[i]; c.push_back (t % 10); t /= 10; } if (t) c.push_back(t); reverse (c.begin (), c.end ()); return c; } int cmp (vector <int> a, vector <int> b) { int la = a.size (), lb = b.size (); if (la != lb) return 1; for (int i = 0; i < la; i ++ ) { if (a[i] != b[i]) return a[i] > b[i]; } return 0; } vector <int> sub (vector <int> a, vector <int> b) { int la = a.size (), lb = b.size (); reverse (a.begin (), a.end ()); reverse (b.begin (), b.end ()); vector <int> c; int t = 0; for (int i = 0; i < la; i ++ ) { t = a[i] - t; if (i < lb) t -= b[i]; c.push_back ((t + 10) % 10); if (t < 0) t = 1; else t = 0; } while (c.size () > 1 && !c.back ()) c.pop_back (); reverse (c.begin (), c.end ()); return c; } vector <int> mul (vector <int> a, int b) { int la = a.size (); reverse (a.begin (), a.end ()); vector <int> c; int t = 0; for (int i = 0; i < la || t; i ++ ) { if (i < la) t += a[i] * b; c.push_back (t % 10); t /= 10; } while (c.size () > 1 && !c.back ()) c.pop_back (); reverse (c.begin (), c.end ()); return c; } vector <int> div (vector <int> a, int b, int &r) { int la = a.size (); reverse (a.begin (), a.end ()); vector <int> c; for (int i = la - 1; i >= 0; i -- ) { r = r * 10 + a[i]; c.push_back (r / b); r %= b; } reverse (c.begin (), c.end ()); while (c.size () > 1 && !c.back ()) c.pop_back (); reverse (c.begin (), c.end ()); return c; } signed main () { // freopen ("double.in", "r", stdin); freopen ("double.out", "w", stdout); scanf ("%s", s + 1); int len = strlen (s + 1); vector <int> n; for (int i = 1; i <= len; i ++ ) n.push_back (s[i] - '0'); vector <int> tmp = n, zero, ans = n; zero.push_back (0); int r = 0; while (cmp (tmp, zero)) { r = 0; tmp = div (tmp, 2, r); ans = sub (ans, tmp); } for (int i = 0; i < ans.size (); i ++ ) printf ("%d", ans[i]); return 0; }