結果
問題 | No.1458 Segment Function |
ユーザー |
![]() |
提出日時 | 2021-03-31 21:59:17 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 10 ms / 2,000 ms |
コード長 | 1,987 bytes |
コンパイル時間 | 1,232 ms |
コンパイル使用メモリ | 129,128 KB |
最終ジャッジ日時 | 2025-01-20 03:29:01 |
ジャッジサーバーID (参考情報) |
judge5 / judge |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 32 |
ソースコード
#include <iostream> #include <iomanip> #include <string> #include <vector> #include <algorithm> #include <utility> #include <functional> #include <set> #include <map> #include <queue> #include <deque> #include <bitset> #include <math.h> #include <random> #include <chrono> #include <assert.h> using namespace std ; using ll = long long ; using ld = long double ; template<class T> using V = vector<T> ; template<class T> using VV = V<V<T>> ; using pll = pair<ll,ll> ; #define all(v) v.begin(),v.end() ll mod = 1000000007 ; long double pie = acos(-1) ; ll INF = 1e18 ; void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;} //void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;} ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;} ll lcm(long long a,long long b){return a/gcd(a,b)*b ;} ll extGCD(ll a,ll b,ll &x,ll &y){ if(b==0){ x = 1 ; y = 0 ; return a ; } ll d = extGCD(b,a%b,y,x) ; y -= a/b*x ; return d ; } void fix_cout(){cout << fixed << setprecision(20) ;} template<class T> void chmax(T &a,T &b){if(a<b) a = b ;} template<class T> void chmin(T &a,T &b){if(a>b) a = b ;} V<ll> cnt = {6,2,5,5,4,5,6,4,7,6} ; ll f(ll num){ ll res = 0 ; while(num>0){ res += cnt[num%10] ; num /= 10 ; } return res ; } int main(){ string p,n ; cin >> p >> n ; if(n=="0"){ cout << p << endl ; return 0 ; } ll sub = 0 ; for(int i=0;i<p.size();i++){ if(p[i]=='-') sub++ ; else sub += cnt[p[i]-'0'] ; } ll pp = sub ; int tmp = 1 ; while(sub>=10){ tmp++ ; sub = f(sub) ; } if(n.size()<=10){ ll m = stol(n) ; if(tmp>=m||m<=1e6){ sub = pp ; for(int i=0;i<m-1;i++) sub = f(sub) ; cout << sub << endl ; return 0 ; } } V<int> ans = {6,5,5,5,4,5,6,4,4,6} ; cout << ans[sub] << endl ; }