Nu am nici cea mai mica idee de ce obtin WA pe TMUL (dupa ce trec de asta vreau sa nu scot TLE pe MUL). L-am testat in toate felurile si da bine.
#include <stdio.h>
#include <ctype.h>
#define base 1000000000
#define len 9
#define N 1113
unsigned long long first[N], second[N], last[2 * N];
inline void init()
{
char chr;
unsigned short cnt;
unsigned long total;
first[0] = second[0] = 0;
cnt = 0;
total = getchar() - '0';
while (!isspace(chr = getchar())) {
if (++cnt != len) {
total = total * 10 + chr - '0';
} else {
first[++first[0]] = total;
total = chr - '0';
cnt = 0;
}
}
first[++first[0]] = total;
cnt = 0;
total = getchar() - '0';
while (!(isspace(chr = getchar()) || chr == EOF)) {
if (++cnt != len) {
total = total * 10 + chr - '0';
} else {
second[++second[0]] = total;
total = chr - '0';
cnt = 0;
}
}
second[++second[0]] = total;
}
inline void zfill(unsigned long nr, char str[])
{
unsigned short cnt = 0, i = 0;
if (!nr) {
cnt = 1;
} else {
while (nr > 0) {
++cnt;
nr /= 10;
}
}
for (; i < len - cnt; ++i) {
str[i] = '0';
}
str[i] = 0;
}
inline void process()
{
unsigned long long temp = 0;
unsigned short i, j;
char str[10];
if (!first[1] || !second[1]) {
putchar('0');
} else {
last[0] = first[0] + second[0] - 1;
for (i = first[0]; i > 0; --i) {
for (j = second[0]; j > 0; --j) {
last[i + j - 1] += first[i] * second[j] + temp;
temp = last[i + j - 1] / base;
last[i + j - 1] %= base;
}
}
if (temp) {
printf("%lu", (unsigned long) temp);
}
for (i = 1; i <= last[0]; ++i) {
if (i != 1) {
zfill((unsigned long) last[i], str);
} else {
str[0] = 0;
}
printf("%s%lu", str, (unsigned long) last[i]);
last[i] = 0;
}
}
putchar('\n');
}
int main()
{
short nr;
freopen("mul.in", "rt", stdin);
scanf("%hd\n", &nr);
while (nr-- > 0) {
init();
process();
}
return 0;
}
Edit ... am rezolvat, nu aveam grija la mutiplul lungimii bazei si la transport.
http://pastebin.com/iMmPUa4d