#ifndef DUCK_FASTIO_H
#define DUCK_FASTIO_H
typedef unsigned long duck_u64;
typedef long duck_i64;
typedef struct {
duck_u64 abi_version;
const char *stdin_ptr;
duck_u64 stdin_size;
char *stdout_ptr;
duck_u64 stdout_limit;
duck_u64 stdout_size;
char *stderr_ptr;
duck_u64 stderr_limit;
duck_u64 stderr_size;
const char *ib_ptr;
duck_u64 ib_limit;
char *ob_ptr;
duck_u64 ob_limit;
duck_u64 tsc_frequency;
} __attribute__((packed)) DuckInfo;
static __attribute__((always_inline)) inline DuckInfo *duck_info(long argc, char **argv) {
char **p = argv + argc + 1;
while (*p) ++p;
duck_u64 *aux = (duck_u64 *)(p + 1);
while (aux[0]) {
if (aux[0] == 0x6b637564UL) return (DuckInfo *)aux[1];
aux += 2;
}
return (DuckInfo *)0;
}
static __attribute__((always_inline)) inline duck_u64 duck_read_u64(const char **cursor) {
const char *p = *cursor;
while ((unsigned char)(*p - '0') > 9) ++p;
duck_u64 value = 0;
do {
value = value * 10 + (unsigned char)(*p - '0');
++p;
} while ((unsigned char)(*p - '0') <= 9);
*cursor = p;
return value;
}
static __attribute__((always_inline)) inline duck_i64 duck_read_i64(const char **cursor) {
const char *p = *cursor;
while (*p != '-' && (unsigned char)(*p - '0') > 9) ++p;
int negative = *p == '-';
p += negative;
duck_u64 value = 0;
do {
value = value * 10 + (unsigned char)(*p - '0');
++p;
} while ((unsigned char)(*p - '0') <= 9);
*cursor = p;
return negative ? -(duck_i64)value : (duck_i64)value;
}
static __attribute__((always_inline)) inline char *duck_write_u64(char *out, duck_u64 value) {
char tmp[24];
unsigned n = 0;
do {
tmp[n++] = (char)('0' + value % 10);
value /= 10;
} while (value);
do *out++ = tmp[--n]; while (n);
return out;
}
static __attribute__((always_inline)) inline char *duck_write_i64(char *out, duck_i64 value) {
if (value < 0) {
*out++ = '-';
return duck_write_u64(out, (duck_u64)(-value));
}
return duck_write_u64(out, (duck_u64)value);
}
static __attribute__((always_inline, noreturn)) inline void duck_exit(void) {
__asm__ volatile("mov $60,%%eax;xor %%edi,%%edi;syscall" ::: "rax", "rdi", "rcx", "r11", "memory");
__builtin_unreachable();
}
#endif
typedef unsigned int u32;
static __attribute__((always_inline)) inline u32 mul_mod(u32 a, u32 b) {
return (u32)((duck_u64)a * b % 1000000007u);
}
static __attribute__((always_inline)) inline u32 pow_mod(u32 a, u32 e) {
u32 r = 1;
while (e) {
if (e & 1) r = mul_mod(r, a);
a = mul_mod(a, a);
e >>= 1;
}
return r;
}
__attribute__((noreturn))
void __libc_start_main(void *unused, long argc, char **argv) {
(void)unused;
DuckInfo *info = duck_info(argc, argv);
const char *p = info->stdin_ptr;
u32 n = (u32)duck_read_u64(&p);
u32 m = (u32)duck_read_u64(&p);
if (n > m) {
u32 t = n;
n = m;
m = t;
}
u32 answer;
if (n == 1) {
answer = pow_mod(2, m);
} else if (n == 2) {
answer = mul_mod(4, pow_mod(3, m - 1));
} else if (n == 3) {
answer = mul_mod(112, pow_mod(3, m - 3));
} else {
static const u32 square[9] = {
0, 0, 0, 0, 912, 7136, 56768, 453504, 3626752
};
static const u32 next_column[9] = {
0, 0, 0, 0, 2688, 21312, 170112, 1360128, 10879488
};
if (m == n) {
answer = square[n];
} else {
answer = mul_mod(next_column[n], pow_mod(3, m - n - 1));
}
}
char *out = info->stdout_ptr;
out = duck_write_u64(out, answer);
*out++ = '\n';
info->stdout_size = (duck_u64)(out - info->stdout_ptr);
duck_exit();
}
int main(void) {}
| Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
| Testcase #1 | 3.04 us | 8 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #2 | 2.18 us | 8 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #3 | 2.79 us | 8 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #4 | 2.46 us | 8 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #5 | 2.7 us | 8 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #6 | 3.16 us | 8 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #7 | 3.12 us | 8 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #8 | 3.03 us | 8 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #9 | 2.96 us | 8 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #10 | 3.01 us | 8 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #11 | 2.9 us | 8 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #12 | 2.85 us | 8 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #13 | 3.09 us | 8 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #14 | 3.12 us | 8 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #15 | 2.82 us | 8 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #16 | 3.09 us | 8 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #17 | 3 us | 8 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #18 | 3.38 us | 8 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #19 | 3.02 us | 8 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #20 | 3.13 us | 8 KB | Accepted | Score: 5 | 显示更多 |