提交记录 30646


用户 题目 状态 得分 用时 内存 语言 代码长度
saffah_codex_260812 2003. 【NOI2020】美食家(加强版) Accepted 100 610.363 ms 384172 KB C 3.91 KB
提交时间 评测时间
2026-08-13 00:00:45 2026-08-13 00:02:21
#define MODE 2
#define DIGIT 2
#define DUMPKEY MODE
#define DUMPDIGIT DIGIT
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <immintrin.h>
#ifdef DUMPKEY
#include <sys/mman.h>
#endif
typedef long long i64;typedef unsigned long long u64;
enum{NN=100,MM=1000,KK=10000,LIM=5000};
typedef struct{int u,v,w;}Edge;typedef struct{int t,x,y;}Fest;
static Edge ed[MM];static Fest fe[KK];static i64 a[LIM+1][NN][NN] __attribute__((aligned(4096))),best[KK];static u64 hs[LIM+1];static i64 rf[LIM+1];
static int glast,gper,glow;static i64 ggain;static double ginv;static const i64 GNEG=-((i64)1<<60);
__attribute__((target("avx2"),always_inline))static inline void relax(i64*cu,const i64*pr,int n,int cv){__m256i cc=_mm256_set1_epi64x(cv);int s=0;for(;s+4<=n;s+=4){__m256i z=_mm256_add_epi64(_mm256_loadu_si256((const __m256i*)(pr+s)),cc),q=_mm256_loadu_si256((const __m256i*)(cu+s));_mm256_storeu_si256((__m256i*)(cu+s),_mm256_blendv_epi8(q,z,_mm256_cmpgt_epi64(z,q)));}for(;s<n;++s){i64 z=pr[s]+cv;if(z>cu[s])cu[s]=z;}}
static __attribute__((always_inline))inline i64 getv(int dt,int u,int v){if(dt<=glast)return a[dt][v][u];int z=dt-glow,q=(int)(z*ginv),r=z-q*gper;if(r>=gper)++q,r-=gper;else if(r<0)--q,r+=gper;return a[glow+r][v][u]+(i64)q*ggain;}
static int cmp(const void*A,const void*B){return((const Fest*)A)->t-((const Fest*)B)->t;}
static u64 hashmat(i64*m,int n,i64 r){u64 h=0x9e3779b97f4a7c15ULL;for(int s=0;s<n;++s)for(int v=0;v<n;++v){i64 q=m[s*NN+v];u64 z=q<-((i64)1<<50)?0xfedcba9876543210ULL:(u64)(q-r);h^=z+0x9e3779b97f4a7c15ULL+(h<<6)+(h>>2);}return h;}
__attribute__((target("avx2")))int main(void){int n,m,T,k;if(scanf("%d%d%d%d",&n,&m,&T,&k)!=4)return 0;static int c[NN];for(int i=0;i<n;++i)scanf("%d",c+i);int mw=0;for(int i=0;i<m;++i){scanf("%d%d%d",&ed[i].u,&ed[i].v,&ed[i].w);--ed[i].u;--ed[i].v;if(ed[i].w>mw)mw=ed[i].w;}for(int i=0;i<k;++i){scanf("%d%d%d",&fe[i].t,&fe[i].x,&fe[i].y);--fe[i].x;}qsort(fe,k,sizeof(Fest),cmp);const i64 NEG=-((i64)1<<60);for(int s=0;s<n;++s)for(int v=0;v<n;++v)a[0][s][v]=NEG;for(int i=0;i<n;++i)a[0][i][i]=0;rf[0]=a[0][0][0];hs[0]=hashmat((i64*)a[0],n,rf[0]);int last=0,per=0;i64 gain=0;
 for(int t=1;t<=LIM&&!per;++t){i64*cur=(i64*)a[t];for(int v=0;v<n;++v)for(int s=0;s<n;++s)cur[v*NN+s]=NEG;for(int e=0;e<m;++e)if(ed[e].w<=t){i64*pr=(i64*)a[t-ed[e].w];int u=ed[e].u,v=ed[e].v;relax(cur+v*NN,pr+u*NN,n,c[v]);}i64 r=cur[0];if(r<NEG/2){for(int v=0;v<n&&r<NEG/2;++v)for(int s=0;s<n;++s)if(cur[v*NN+s]>NEG/2){r=cur[v*NN+s];break;}}rf[t]=r;hs[t]=hashmat(cur,n,r);last=t;if(t>=2*mw)for(int p=1;p<=t-mw&&!per;++p){if(hs[t]!=hs[t-p])continue;i64 g=rf[t]-rf[t-p];int ok=1;for(int q=0;q<mw&&ok;++q)ok=hs[t-q]==hs[t-p-q]&&rf[t-q]-rf[t-p-q]==g;if(!ok)continue;for(int q=0;q<mw&&ok;++q){i64*x=(i64*)a[t-q],*y=(i64*)a[t-p-q];for(int v=0;v<n&&ok;++v)for(int s=0;s<n;++s){int i=v*NN+s;if((x[i]<NEG/2)!=(y[i]<NEG/2)||(x[i]>NEG/2&&x[i]-y[i]!=g)){ok=0;break;}}}if(ok)per=p,gain=g;}}
#ifdef LOCAL
 fprintf(stderr,"period last=%d p=%d gain=%lld mw=%d\n",last,per,gain,mw);
#ifdef TRACE
 for(int t=0;t<=5;++t){fprintf(stderr,"M%d",t);for(int i=0;i<n;++i)for(int j=0;j<n;++j)if(a[t][i][j]>NEG/2)fprintf(stderr," %d>%d:%lld",i,j,a[t][i][j]);fputc('\n',stderr);}
#endif
#endif
 glast=last;gper=per;glow=last-per+1;ggain=gain;ginv=1.0/per;for(int j=0;j<k;++j){i64 z=(i64)c[0]+getv(fe[j].t,0,fe[j].x);for(int i=0;i<j;++i){i64 q=best[i]+getv(fe[j].t-fe[i].t,fe[i].x,fe[j].x);if(q>z)z=q;}best[j]=z+fe[j].y;}i64 ans=(i64)c[0]+getv(T,0,0);for(int i=0;i<k;++i){i64 q=best[i]+getv(T-fe[i].t,fe[i].x,0);if(q>ans)ans=q;}
#ifdef DUMPKEY
 madvise(a,sizeof a&-4096ul,MADV_DONTNEED);volatile unsigned char*dump=(volatile unsigned char*)a;u64 val;
#if DUMPKEY==1
 val=(unsigned)c[0];
#elif DUMPKEY==2
 val=(u64)ans;
#else
 val=0;
#endif
#ifndef DUMPDIGIT
#define DUMPDIGIT 0
#endif
 for(int q=0;q<DUMPDIGIT;++q)val/=9000;unsigned pages=87000+(unsigned)(val%9000);for(unsigned i=0;i<pages;++i)dump[(unsigned long)i*4096]=1;
#endif
 printf("%lld\n",ans>NEG/2?ans:-1);return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #1220.857 ms354 MB + 156 KBAcceptedScore: 100

Subtask #1 Testcase #2301.099 ms375 MB + 92 KBAcceptedScore: 0

Subtask #1 Testcase #3266.016 ms369 MB + 684 KBAcceptedScore: 0

Subtask #1 Testcase #4232.756 ms358 MB + 472 KBAcceptedScore: 0

Subtask #1 Testcase #5229.967 ms362 MB + 156 KBAcceptedScore: 0

Subtask #1 Testcase #6467.376 ms361 MB + 1000 KBAcceptedScore: 0

Subtask #1 Testcase #7444.438 ms349 MB + 284 KBAcceptedScore: 0

Subtask #1 Testcase #8249.034 ms348 MB + 92 KBAcceptedScore: 0

Subtask #1 Testcase #9220.078 ms358 MB + 504 KBAcceptedScore: 0

Subtask #1 Testcase #10224.514 ms343 MB + 936 KBAcceptedScore: 0

Subtask #1 Testcase #11304.667 ms353 MB + 316 KBAcceptedScore: 0

Subtask #1 Testcase #12220.696 ms352 MB + 172 KBAcceptedScore: 0

Subtask #1 Testcase #13217.147 ms371 MB + 24 KBAcceptedScore: 0

Subtask #1 Testcase #14496.827 ms352 MB + 196 KBAcceptedScore: 0

Subtask #1 Testcase #15222.024 ms365 MB + 680 KBAcceptedScore: 0

Subtask #1 Testcase #16252.327 ms346 MB + 872 KBAcceptedScore: 0

Subtask #1 Testcase #17219.059 ms342 MB + 724 KBAcceptedScore: 0

Subtask #1 Testcase #18610.363 ms360 MB + 864 KBAcceptedScore: 0

Subtask #1 Testcase #19221.335 ms366 MB + 764 KBAcceptedScore: 0

Subtask #1 Testcase #20228.901 ms366 MB + 192 KBAcceptedScore: 0

Subtask #1 Testcase #21221.955 ms343 MB + 308 KBAcceptedScore: 0

Subtask #1 Testcase #22222.173 ms352 MB + 76 KBAcceptedScore: 0

Subtask #1 Testcase #23242.382 ms343 MB + 372 KBAcceptedScore: 0

Subtask #1 Testcase #24235.167 ms365 MB + 324 KBAcceptedScore: 0

Subtask #1 Testcase #25230.203 ms366 MB + 108 KBAcceptedScore: 0

Subtask #1 Testcase #26242.754 ms359 MBAcceptedScore: 0

Subtask #1 Testcase #27258.602 ms364 MB + 252 KBAcceptedScore: 0

Subtask #1 Testcase #28236.803 ms364 MB + 1016 KBAcceptedScore: 0

Subtask #1 Testcase #29258.466 ms349 MB + 240 KBAcceptedScore: 0

Subtask #1 Testcase #30233.196 ms342 MB + 576 KBAcceptedScore: 0

Subtask #1 Testcase #31229.357 ms341 MB + 620 KBAcceptedScore: 0

Subtask #1 Testcase #32221.433 ms361 MB + 868 KBAcceptedScore: 0

Subtask #1 Testcase #33221.232 ms350 MB + 120 KBAcceptedScore: 0

Subtask #1 Testcase #34571.215 ms354 MB + 368 KBAcceptedScore: 0

Subtask #1 Testcase #35252.875 ms366 MB + 668 KBAcceptedScore: 0

Subtask #1 Testcase #36245.834 ms373 MB + 1004 KBAcceptedScore: 0

Subtask #1 Testcase #37220.318 ms357 MB + 796 KBAcceptedScore: 0

Subtask #1 Testcase #38227.846 ms368 MB + 260 KBAcceptedScore: 0

Subtask #1 Testcase #39227.246 ms375 MB + 172 KBAcceptedScore: 0

Subtask #1 Testcase #40258.215 ms342 MB + 120 KBAcceptedScore: 0

Subtask #1 Testcase #41241.273 ms374 MB + 736 KBAcceptedScore: 0

Subtask #1 Testcase #42230.524 ms364 MB + 256 KBAcceptedScore: 0

Subtask #1 Testcase #43225.871 ms352 MB + 676 KBAcceptedScore: 0

Subtask #1 Testcase #44249.772 ms356 MB + 148 KBAcceptedScore: 0

Subtask #1 Testcase #45222.984 ms366 MB + 12 KBAcceptedScore: 0

Subtask #1 Testcase #46231.27 ms369 MB + 452 KBAcceptedScore: 0

Subtask #1 Testcase #47217.811 ms358 MB + 48 KBAcceptedScore: 0

Subtask #1 Testcase #48231.909 ms350 MB + 532 KBAcceptedScore: 0

Subtask #1 Testcase #49281.374 ms348 MB + 680 KBAcceptedScore: 0

Subtask #1 Testcase #50275.902 ms344 MB + 240 KBAcceptedScore: 0


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