# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
341384 |
2020-12-29T15:34:57 Z |
phathnv |
Multiply (CEOI17_mul) |
C++11 |
|
72 ms |
848 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 12000;
const int INF = 1e9;
int n, m, a[N], b[N], res[N];
void toArray(string &str, int a[]){
reverse(str.begin(), str.end());
int base = 1, cur = 0;
for(char ch : str){
a[cur] += (ch - '0') * base;
base *= 10;
if (base == 1e9){
cur++;
base = 1;
}
}
}
void readInput(){
string sA, sB;
cin >> m >> n;
cin >> sA >> sB;
toArray(sA, a);
toArray(sB, b);
}
void solve(){
m = (m + 8) / 9;
n = (n + 8) / 9;
int base = 1e9;
for(int i = 0; i < m; i++){
int carry = 0;
for(int j = 0; j < n; j++){
ll sum = carry + res[i + j] + (ll) a[i] * b[j];
res[i + j] = sum % base;
carry = sum / base;
}
res[i + n] = carry;
}
int sz = m + n;
while (res[sz] == 0 && sz > 0)
sz--;
cout << res[sz];
for(int i = sz - 1; i >= 0; i--)
cout << setw(9) << setfill('0') << res[i];
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
readInput();
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
2 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
312 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
2 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
312 KB |
Output is correct |
16 |
Correct |
27 ms |
620 KB |
Output is correct |
17 |
Correct |
72 ms |
652 KB |
Output is correct |
18 |
Correct |
8 ms |
620 KB |
Output is correct |
19 |
Correct |
65 ms |
848 KB |
Output is correct |
20 |
Correct |
1 ms |
492 KB |
Output is correct |