- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 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
- 91
- 92
#include <deque>
#include <stdint.h>
#include <iterator>
#include <algorithm>
#include <iostream>
#include <iomanip>
using namespace std;
typedef uint32_t bt;
typedef uint64_t dbt;
typedef deque<bt> bn;
#define cat2(b,e) b##e
#define cat(b,e) cat2(b,e)
#define fsi(i,s,e) for(size_t i(s), cat(i,_end)(e); i<cat(i,_end); ++(i))
#define fe(i,c) for(auto i((c).begin()), cat(i,_end)((c).end()); i!=cat(i,_end); ++(i))
void ml10(bn& n){
n.push_front(0);
}
uint32_t ni(const bn& n, size_t i){
if(n.size()<=i)
return 0;
else
return n[i];
}
size_t ms(const bn& n1, const bn& n2){
return (max) (n1.size(), n2.size());
}
bt gr(dbt tr){
return tr & (numeric_limits<bt>::max)();
}
bt gc(dbt tr){
return (tr & (~((dbt)(numeric_limits<bt>::max)()))) >> (numeric_limits<bt>::digits);
}
void pb(bt b1, bt b2, bt lc, bt& r, bt& c){
dbt tr = ((uint64_t)b1 + b2 + lc);
r = gr(tr);
c = gc(tr);
}
void mb(bt b1, bt b2, bt lc, bt& r, bt& c){
dbt tr = ((uint64_t)b1 * b2 + lc);
r = gr(tr);
c = gc(tr);
}
bn /*constexpr*/ bi(bn n){
reverse(n.begin(), n.end());
return n;
}
bn pl(const bn& n1, const bn& n2){
bn r;
bt c=0,br=0;
size_t ms_ = ms(n1, n2);
//r.reserve(ms_+1);
fsi(i,0,ms_){
pb(ni(n1,i),ni(n2,i),c,br,c);
r.push_back(br);
}
if (c)
r.push_back(c);
return r;
}
bn ml(bn n1, const bn& n2){
bn lr, r;
bt c=0;
//r.reserve(n1.size() + n2.size() + 1);
fsi(i2,0,n2.size()){
fsi(i1, 0, n1.size()){
lr.emplace_back();
mb(n1[i1], n2[i2], c, lr[i1], c);
}
if (c){
lr.push_back(c);
c = 0;
}
r = pl(r, lr);
lr.clear();
ml10(n1);
}
return r;
}
#define STR1(x) #x
#define STR(x) STR1(x)
#define EXPECT_TRUE(expr)\
do{\
if(!(expr))\
cout<<"*****Failed test: \"" STR(expr) "\"" << endl;\
else\
cout << "Test OK: \"" STR(expr) "\"" << endl;\
}while(false)
#define TEST(expr)\
do{\
cout << "Test begined: \"" STR(expr) "\"" << endl;\
(void)(expr);\
} while (false)
И вот мой просмотр аниме закончен.
http://ideone.com/eRJ7FA
main смотри в коментах