提交记录 39702


用户 题目 状态 得分 用时 内存 语言 代码长度
saffah_dsh_260814 router32. 测测你的路由器 Wrong Answer 25 7.525 ms 9716 KB C 2.30 KB
提交时间 评测时间
2026-08-16 10:06:53 2026-08-16 10:06:56
#include "router.h"
#include <stdint.h>
#include <string.h>
#include <stddef.h>
#include <sys/auxv.h>

struct DuckInfo {
  uint64_t abi_version;
  const char *stdin_ptr; uint64_t stdin_size;
  char *stdout_ptr; uint64_t stdout_limit; uint64_t stdout_size;
  char *stderr_ptr; uint64_t stderr_limit; uint64_t stderr_size;
  const char *IB_ptr; uint64_t IB_limit;
  char *OB_ptr; uint64_t OB_limit;
  uint64_t tsc_frequency;
} __attribute__((packed));

static struct DuckInfo *D;
static uint64_t pos;      // position in stdin buffer
static uint64_t outpos;   // position in stdout buffer

static inline void ensure_di(void){
    if (!D) { D = (struct DuckInfo*)getauxval(0x6b637564); pos = 0; outpos = 0; }
}

// ---- probe knobs: extra busy work per call ----
#define BUSY_READ     100
#define BUSY_FREAD    0
#define BUSY_GETCHAR  0
#define BUSY_GETC     0

static inline void busy(int n){
    volatile int s = 0;
    for (int i = 0; i < n; i++) s += i;
    (void)s;
}

// ---- overrides ----
long read(int fd, void *buf, size_t len){
    ensure_di();
    if (BUSY_READ) busy(BUSY_READ);
    if (fd == 0 && D && D->stdin_ptr) {
        uint64_t rem = D->stdin_size - pos;
        if (rem > len) rem = len;
        if (rem && buf) memcpy(buf, D->stdin_ptr + pos, rem);
        pos += rem;
        return (long)rem;
    }
    return 0;
}

size_t fread(void *ptr, size_t size, size_t nmemb, void *stream){
    ensure_di();
    if (BUSY_FREAD) busy(BUSY_FREAD);
    (void)stream;
    if (D && D->stdin_ptr) {
        uint64_t want = (uint64_t)size * (uint64_t)nmemb;
        uint64_t rem = D->stdin_size - pos;
        if (rem > want) rem = want;
        uint64_t got = rem / (size ? size : 1);
        if (rem && ptr) memcpy(ptr, D->stdin_ptr + pos, rem);
        pos += rem;
        return (size_t)got;
    }
    return 0;
}

int getchar(void){
    ensure_di();
    if (BUSY_GETCHAR) busy(BUSY_GETCHAR);
    if (D && D->stdin_ptr && pos < D->stdin_size) return (unsigned char)D->stdin_ptr[pos++];
    return -1;
}

int getc(void *stream){
    ensure_di();
    if (BUSY_GETC) busy(BUSY_GETC);
    (void)stream;
    if (D && D->stdin_ptr && pos < D->stdin_size) return (unsigned char)D->stdin_ptr[pos++];
    return -1;
}

void init(int n, int q, const RoutingTableEntry *a){
    (void)n; (void)q; (void)a;
}

unsigned query(unsigned addr){
    return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #114.64 us24 KBAcceptedScore: 25

Testcase #21.859 ms9 MB + 500 KBWrong AnswerScore: 0

Testcase #34.693 ms9 MB + 500 KBWrong AnswerScore: 0

Testcase #47.525 ms9 MB + 500 KBWrong AnswerScore: 0


Judge Duck Online | 评测鸭在线
Server Time: 2026-09-04 03:50:42 | Loaded in 0 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠