// noip18e 填数游戏 — fast path: no libc init, auxv scan for DuckInfo,
// direct stdin/stdout buffers, closed-form answer.
typedef unsigned long long u64;
struct DI { u64 abi; const char*in; u64 insz; char*out; u64 outlim; u64 outsz; char*err;
u64 errlim; u64 errsz; const char*IB; u64 IBlim; char*OB; u64 OBlim; u64 tscfreq; }
__attribute__((packed));
// f(n,n), f(n,n+1) for n=1..8 ; f(n,m) = f(n,n+1)*3^(m-n-1) for m >= n+1 (n>=2)
static const unsigned long long TAB[9][2] = {
{0,0},
{2ULL, 4ULL},
{12ULL, 36ULL},
{112ULL, 336ULL},
{912ULL, 2688ULL},
{7136ULL, 21312ULL},
{56768ULL, 170112ULL},
{453504ULL, 1360128ULL},
{3626752ULL, 10879488ULL},
};
static inline void raw_exit(void) {
register long rax __asm__("rax") = 60;
register long rdi __asm__("rdi") = 0;
__asm__ volatile("syscall" :: "a"(rax), "D"(rdi) : "rcx", "r11", "memory");
__builtin_unreachable();
}
extern "C" int __libc_start_main(int (*m)(int, char**, char**), int argc, char **argv,
void (*i)(void), void (*f)(void), void (*l)(void),
void *stack_end) {
(void)m; (void)argc; (void)argv; (void)i; (void)f; (void)l; (void)stack_end;
DI *di = (DI *)0x243FFF90ULL; /* 0x400000 + hard_limit - 112 (512MB problems) */
const char *in = di->in;
u64 sz = di->insz, p = 0;
int n = 0, mm = 0;
while (p < sz && in[p] >= '0' && in[p] <= '9') n = n * 10 + (in[p++] - '0');
while (p < sz && (in[p] < '0' || in[p] > '9')) p++;
while (p < sz && in[p] >= '0' && in[p] <= '9') mm = mm * 10 + (in[p++] - '0');
if (n > mm) { int t = n; n = mm; mm = t; }
const u64 MOD = 1000000007ULL;
u64 ans;
if (n == 1) {
u64 b = 2, e = (u64)mm, r = 1;
while (e) { if (e & 1) r = r * b % MOD; b = b * b % MOD; e >>= 1; }
ans = r;
} else if (mm == n) {
ans = TAB[n][0];
} else {
u64 b = 3, e = (u64)(mm - n - 1), r = TAB[n][1] % MOD;
while (e) { if (e & 1) r = r * b % MOD; b = b * b % MOD; e >>= 1; }
ans = r;
}
char buf[14];
int k = 0;
do { buf[k++] = (char)('0' + ans % 10); ans /= 10; } while (ans);
char *o = di->out;
for (int q = 0; q < k; q++) o[q] = buf[k - 1 - q];
o[k++] = '\n';
di->outsz = (u64)k;
raw_exit();
return 0;
}
int main() { return 0; }
| Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
| Testcase #1 | 2.62 us | 8 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #2 | 2.18 us | 8 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #3 | 2.65 us | 8 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #4 | 2.27 us | 8 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #5 | 3.19 us | 8 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #6 | 2.76 us | 8 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #7 | 3.05 us | 8 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #8 | 3 us | 8 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #9 | 2.72 us | 8 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #10 | 3.02 us | 8 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #11 | 3.42 us | 8 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #12 | 2.71 us | 8 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #13 | 2.84 us | 8 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #14 | 2.38 us | 8 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #15 | 2.57 us | 8 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #16 | 2.98 us | 8 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #17 | 3.06 us | 8 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #18 | 3.1 us | 8 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #19 | 3.36 us | 8 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #20 | 2.73 us | 8 KB | Accepted | Score: 5 | 显示更多 |