Submission #490946

#TimeUsernameProblemLanguageResultExecution timeMemory
490946kawaiiMultiply (CEOI17_mul)C++17
0 / 100
70 ms131076 KiB
#include <bits/stdc++.h> using namespace std; string n, m; int a, b; string add(string a, string b){ reverse(a.begin(), a.end()); reverse(b.begin(), b.end()); a.push_back('0'); b.push_back('0'); while(a.size() > b.size()) b.push_back('0'); while(a.size() < b.size()) a.push_back('0'); int cnt = 0, du = 0; string res = ""; for(int i = 0; i < a.size(); i++){ cnt = a[i] + b[i] - 96 + du; du = cnt / 10; res.push_back(char(cnt % 10 + 48)); } while(res.back() == '0') res.pop_back(); reverse(res.begin(), res.end()); return res; } string chia(string a){ string res = ""; int p = 0; for(int i = 0; i < a.size(); i++){ p = p * 10 + a[i] - 48; if(p >= 2){ res.push_back(char(p / 2 + 48)); p %= 2; } else res.push_back('0'); } reverse(res.begin(), res.end()); while(res.back() == '0') res.pop_back(); reverse(res.begin(), res.end()); return res; } string nhan(string a, string b){ if(b == "1") return a; string ans = nhan(a, chia(b)); //cout << a <<" "<< chia(b) << "\n"; if(b.back() % 2 == 0) return add(ans, ans); else return add(add(ans, ans), a); } void solve(){ cout << nhan(n, m); } signed main(){ ios_base::sync_with_stdio(NULL); cin.tie(nullptr); cout.tie(nullptr); cin >> a >> b >> n >> m; solve(); }

Compilation message (stderr)

mul.cpp: In function 'std::string add(std::string, std::string)':
mul.cpp:15:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |     for(int i = 0; i < a.size(); i++){
      |                    ~~^~~~~~~~~~
mul.cpp: In function 'std::string chia(std::string)':
mul.cpp:28:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     for(int i = 0; i < a.size(); i++){
      |                    ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...