Submission #64784


ソースコード

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
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
const char newl = '\n';
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}
template<typename T=int>
vector<T> read(size_t n){
vector<T> ts(n);
for(size_t i=0;i<n;i++) cin>>ts[i];
return ts;
}
//INSERT ABOVE HERE
string add(string a,string b){
if(a=="0") return b;
if(b=="0") return a;
int n=max(a.size(),b.size())+1;
while((int)a.size()<n) a+='0';
while((int)b.size()<n) b+='0';
string c(n,'0');
for(int i=0,carry=0;i<n;i++){
int d=(a[i]-'0')+(b[i]-'0')+carry;
carry=(d>=10);
d%=10;
c[i]='0'+d;
}
// cout<<a<<' '<<b<<' '<<c<<endl;
while(c.back()=='0') c.pop_back();
// cout<<a<<' '<<b<<' '<<c<<endl;
return c;
}
string sub(string a,string b){
int n=max(a.size(),b.size())+1;
while((int)a.size()<n) a+='0';
while((int)b.size()<n) b+='0';
string c(n,'0');
for(int i=0,carry=0;i<n;i++){
int d=(a[i]-'0')-((b[i]-'0')+carry);
carry=(d<0);
if(carry) d+=10;
c[i]='0'+d;
}
return c;
}
string conv(string s){
map<char, string> idx;
idx['0']="0";
idx['1']="1";
idx['2']="2";
idx['3']="3";
idx['4']="-";
idx['5']="4";
idx['6']="5";
idx['7']="6";
idx['8']="7";
idx['9']="-";
string r="0";
for(char c:s){
r=add(r,r);
r=add(r,r);
r=add(r,r);
// cout<<r<<endl;
r=add(r,idx[c]);
}
// cout<<s<<":"<<r<<endl;
return r;
}
signed main(){
cin.tie(0);
ios::sync_with_stdio(0);
string p,q;
cin>>p>>q;
auto r=sub(conv(q),conv(p));
//cout<<r<<endl;
while(r.back()=='0') r.pop_back();
reverse(r.begin(),r.end());
cout<<r<<newl;
return 0;
}

ステータス

項目 データ
問題 1456 - 旅館の客室番号
ユーザー名 syoribu
投稿日時 2020-11-20 12:26:00
言語 C++17
状態 Accepted
得点 7
ソースコード長 1904 Byte
最大実行時間 31 ms
最大メモリ使用量 724 KB

セット

セット 得点 Cases
1 ALL 7 / 7 *

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
in1 AC 21 ms 604 KB
1
in2 AC 21 ms 724 KB
1
in3 AC 24 ms 632 KB
1
in4 AC 20 ms 588 KB
1
in5 AC 19 ms 676 KB
1
in6 AC 18 ms 504 KB
1
in7 AC 21 ms 460 KB
1
in8 AC 28 ms 544 KB
1
in9 AC 25 ms 628 KB
1
in10 AC 19 ms 560 KB
1
in11 AC 26 ms 392 KB
1
in12 AC 21 ms 472 KB
1
in13 AC 24 ms 556 KB
1
in14 AC 21 ms 508 KB
1
in15 AC 31 ms 588 KB
1
in16 AC 20 ms 540 KB
1
in17 AC 21 ms 612 KB
1
in18 AC 19 ms 692 KB
1
in19 AC 23 ms 644 KB
1
in20 AC 24 ms 552 KB
1