提交记录 40371


用户 题目 状态 得分 用时 内存 语言 代码长度
saffah_dsh_260814 1004. 【模板题】高精度乘法 Wrong Answer 0 1.795 ms 16228 KB C++ 5.06 KB
提交时间 评测时间
2026-08-17 23:25:50 2026-08-17 23:25:52
// 1004 input-structure probe (dirty-page mem-channel).
// Reads the raw judge input via DuckInfo stdin_ptr, computes ONE statistic per
// run, and encodes it into the number of dirty 4KB pages (memset big[]).
// Memory (KiB) = baseline + value*4. MODE/ARG selected via text substitution.
#include <sys/auxv.h>
#include <stdint.h>
#include <string.h>
#include <stdlib.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));

#define MODE 3
#define ARG  2

static char big[66000*4096] __attribute__((aligned(4096)));

static inline uint64_t fnv64(const char* p, uint64_t n){
  uint64_t h=1469598103934665603ULL;
  for(uint64_t i=0;i<n;i++){ h ^= (unsigned char)p[i]; h *= 1099511628211ULL; }
  return h;
}

int main(){
  DuckInfo* di=(DuckInfo*)getauxval(0x6b637564ull);
  const char* in=di->stdin_ptr; uint64_t n=di->stdin_size;
  const char* p=in; const char* e=in+n;
  while(p<e && (*p=='\n'||*p=='\r'||*p==' '||*p=='\t')) p++;
  const char* as=p; while(p<e && *p>='0'&&*p<='9') p++; const char* ae=p;
  while(p<e && (*p=='\n'||*p=='\r'||*p==' '||*p=='\t')) p++;
  const char* bs=p; while(p<e && *p>='0'&&*p<='9') p++; const char* be=p;
  uint64_t na=(uint64_t)(ae-as), nb=(uint64_t)(be-bs);

  uint64_t value=0;
  switch(MODE){
    case 0: value=(uint64_t)ARG; break; // calibration: touch ARG pages
    case 1: { // flags: a==b, a all9, b all9, ldz a, ldz b, first-char checks
      int aeqb = (na==nb && memcmp(as,bs,na)==0);
      int aall9=1,ball9=1;
      for(uint64_t i=0;i<na;i++) if(as[i]!='9'){aall9=0;break;}
      for(uint64_t i=0;i<nb;i++) if(bs[i]!='9'){ball9=0;break;}
      uint64_t ldza=0,ldzb=0; while(ldza<na && as[ldza]=='0')ldza++; while(ldzb<nb && bs[ldzb]=='0')ldzb++;
      value = (aeqb?1:0) | (aall9?2:0) | (ball9?4:0) | (ldza>0?8:0) | (ldzb>0?16:0)
            | (as[0]=='1'?32:0) | (bs[0]=='1'?64:0) | (as[0]=='9'?128:0) | (bs[0]=='9'?256:0);
      value += 1000; // offset well above baseline
      break;
    }
    case 2: { // fnv64 hash chunk, 16 bits (ARG = 0..3)
      uint64_t h=fnv64(in,n);
      value = (h >> (ARG*16)) & 0xFFFF;
      break;
    }
    case 3: { // first 4 decimal digits of a (ARG = block 0..)
      uint64_t blk=0; uint64_t start=ARG*4;
      for(int k=0;k<4;k++){ uint64_t idx=start+k; blk=blk*10 + (idx<na ? (uint64_t)(as[idx]-'0') : 0u); }
      value=blk;
      break;
    }
    case 4: { // first 4 decimal digits of b (ARG = block 0..)
      uint64_t blk=0; uint64_t start=ARG*4;
      for(int k=0;k<4;k++){ uint64_t idx=start+k; blk=blk*10 + (idx<nb ? (uint64_t)(bs[idx]-'0') : 0u); }
      value=blk;
      break;
    }
    case 5: { // leading zeros of a, chunk ARG (0=low16,1=high16)
      uint64_t z=0; while(z<na && as[z]=='0') z++;
      value=(z>>(ARG*16))&0xFFFF;
      break;
    }
    case 6: { // count of '0' digits in a, chunk ARG
      uint64_t zc=0; for(uint64_t i=0;i<na;i++) if(as[i]=='0')zc++;
      value=(zc>>(ARG*16))&0xFFFF;
      break;
    }
    case 7: { // digit sum of a, chunk ARG
      uint64_t s=0; for(uint64_t i=0;i<na;i++) s+=(uint64_t)(as[i]-'0');
      value=(s>>(ARG*16))&0xFFFF;
      break;
    }
    case 8: { // last 4 decimal digits of a (ARG = block from end)
      uint64_t blk=0; uint64_t start=na-4-ARG*4;
      for(int k=0;k<4;k++){ uint64_t idx=start+k; blk=blk*10 + (idx<na ? (uint64_t)(as[idx]-'0') : 0u); }
      value=blk;
      break;
    }
    case 9: { // last 4 decimal digits of b (ARG = block from end)
      uint64_t blk=0; uint64_t start=nb-4-ARG*4;
      for(int k=0;k<4;k++){ uint64_t idx=start+k; blk=blk*10 + (idx<nb ? (uint64_t)(bs[idx]-'0') : 0u); }
      value=blk;
      break;
    }
    case 10: { // flags2: complementary, reverse, same-prefix, zero-fractions
      int comp=1, rev=1;
      for(uint64_t i=0;i<na;i++){ if((as[i]-'0')+(bs[i]-'0')!=9){comp=0;break;} }
      for(uint64_t i=0;i<na;i++){ if(as[i]!=bs[na-1-i]){rev=0;break;} }
      uint64_t zca=0,zcb=0;
      for(uint64_t i=0;i<na;i++){ if(as[i]=='0')zca++; if(bs[i]=='0')zcb++; }
      int samepre = (na>=4 && nb>=4 && as[0]==bs[0]&&as[1]==bs[1]&&as[2]==bs[2]&&as[3]==bs[3]);
      value = (comp?1:0) | (rev?2:0) | (samepre?4:0)
            | (zca>150000?8:0) | (zcb>150000?16:0)
            | (zca>300000?32:0) | (zcb>300000?64:0)
            | (as[0]==bs[0]?128:0);
      value += 1000;
      break;
    }
    case 11: { // count of '0' digits in b, chunk ARG
      uint64_t zc=0; for(uint64_t i=0;i<nb;i++) if(bs[i]=='0')zc++;
      value=(zc>>(ARG*16))&0xFFFF;
      break;
    }
    case 12: { // digit sum of b, chunk ARG
      uint64_t s=0; for(uint64_t i=0;i<nb;i++) s+=(uint64_t)(bs[i]-'0');
      value=(s>>(ARG*16))&0xFFFF;
      break;
    }
    default: value=0; break;
  }

  if(value>65500) value=65500;
  memset(big, 1, (size_t)(value*4096));

  asm volatile("mov $60, %%eax; xor %%edi, %%edi; syscall" ::: "rax","rdi","rcx","r11","memory");
  __builtin_unreachable();
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #11.795 ms15 MB + 868 KBWrong AnswerScore: 0


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