結果
| 問題 |
No.219 巨大数の概算
|
| コンテスト | |
| ユーザー |
Kmcode1
|
| 提出日時 | 2015-05-29 23:40:01 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,308 bytes |
| コンパイル時間 | 1,236 ms |
| コンパイル使用メモリ | 111,772 KB |
| 実行使用メモリ | 17,344 KB |
| 最終ジャッジ日時 | 2024-07-06 12:12:07 |
| 合計ジャッジ時間 | 6,659 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 1 |
| other | TLE * 1 -- * 50 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:122:32: warning: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wformat=]
122 | printf("%d %d %d\n", a[0]-'0', a[1]-'0', a.size()-1);
| ~^ ~~~~~~~~~~
| | |
| int std::__cxx11::basic_string<char>::size_type {aka long unsigned int}
| %ld
main.cpp:114:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
114 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
main.cpp:118:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
118 | scanf("%s", buf);
| ~~~~~^~~~~~~~~~~
main.cpp:119:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
119 | scanf("%lld", &b);
| ~~~~~^~~~~~~~~~~~
ソースコード
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cctype>
#include<cstdlib>
#include<algorithm>
#include<bitset>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<ctime>
#include<complex>
#include<functional>
#include<climits>
#include<cassert>
#include<iterator>
#include<unordered_map>
#include<unordered_set>
#include<random>
using namespace std;
string pluss(string a, string b, bool flag = false){
if (!flag){
reverse(a.begin(), a.end());
reverse(b.begin(), b.end());
}
if (a.size() > b.size()){
swap(a, b);
}
string ans;
ans.clear();
long long int want = 0;
for (int i = 0; i < a.size(); i++){
long long int val = a[i] - '0';
val += b[i] - '0';
val += want;
want = val / 10LL;
val %= 10LL;
ans.push_back(val + '0');
}
for (int j = a.size(); j < b.size(); j++){
long long int val = 0;
val += b[j] - '0';
val += want;
want = val / 10LL;
val %= 10LL;
ans.push_back(val + '0');
}
while (want){
ans.push_back(want % 10 + '0');
want /= 10;
}
if (!flag){
reverse(ans.begin(), ans.end());
}
return ans;
}
string mult(string a, string b, bool flag = false){
if (!flag){
reverse(a.begin(), a.end());
reverse(b.begin(), b.end());
}
string ans = "0";
string pas;
string kari;
pas.clear();
for (int i = 0; i < b.size(); i++){
long long int bb = b[i] - '0';
long long int tmp = 0;
kari = pas;
for (int j = 0; j < a.size(); j++){
long long int val = (long long int)(a[j] - '0')*bb;
val += tmp;
tmp = val / 10LL;
val %= 10LL;
kari.push_back(val + '0');
}
while (tmp){
kari.push_back((tmp % 10LL) + '0');
tmp /= 10LL;
}
ans = pluss(ans, kari, true);
//end
pas.push_back('0');
}
if (!flag){
reverse(ans.begin(), ans.end());
}
return ans;
}
string ppow(string a, long long int b){
string res = "1";
while (b){
if ((b & 1LL)){
res = mult(res,a);
}
a = mult(a, a);
b >>= 1LL;
}
return res;
}
char buf[20];
int main(){
int n;
scanf("%d", &n);
while (n--){
string a;
long long int b;
scanf("%s", buf);
scanf("%lld", &b);
a = buf;
a = ppow(a, b);
printf("%d %d %d\n", a[0]-'0', a[1]-'0', a.size()-1);
}
return 0;
}
Kmcode1