結果
問題 | No.971 いたずらっ子 |
ユーザー | LayCurse |
提出日時 | 2020-01-17 23:14:15 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 861 ms / 2,000 ms |
コード長 | 5,174 bytes |
コンパイル時間 | 3,036 ms |
コンパイル使用メモリ | 213,916 KB |
実行使用メモリ | 42,496 KB |
最終ジャッジ日時 | 2024-11-07 11:34:37 |
合計ジャッジ時間 | 9,624 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 861 ms
42,496 KB |
testcase_01 | AC | 854 ms
42,496 KB |
testcase_02 | AC | 595 ms
33,792 KB |
testcase_03 | AC | 594 ms
42,496 KB |
testcase_04 | AC | 556 ms
40,320 KB |
testcase_05 | AC | 592 ms
42,496 KB |
testcase_06 | AC | 444 ms
34,176 KB |
testcase_07 | AC | 6 ms
5,248 KB |
testcase_08 | AC | 127 ms
14,592 KB |
testcase_09 | AC | 118 ms
14,208 KB |
testcase_10 | AC | 3 ms
5,248 KB |
testcase_11 | AC | 2 ms
5,248 KB |
testcase_12 | AC | 2 ms
5,248 KB |
testcase_13 | AC | 2 ms
5,248 KB |
testcase_14 | AC | 5 ms
7,552 KB |
testcase_15 | AC | 2 ms
5,248 KB |
testcase_16 | AC | 2 ms
5,248 KB |
testcase_17 | AC | 2 ms
5,248 KB |
testcase_18 | AC | 2 ms
5,248 KB |
testcase_19 | AC | 2 ms
5,248 KB |
testcase_20 | AC | 2 ms
5,248 KB |
testcase_21 | AC | 2 ms
5,248 KB |
testcase_22 | AC | 2 ms
5,248 KB |
testcase_23 | AC | 2 ms
5,248 KB |
testcase_24 | AC | 2 ms
5,248 KB |
ソースコード
#pragma GCC optimize ("Ofast") #include<bits/stdc++.h> using namespace std; void *wmem; char memarr[96000000]; template<class T> inline void walloc1d(T **arr, int x, void **mem = &wmem){ static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; (*mem) = (void*)( ((char*)(*mem)) + skip[((unsigned long long)(*mem)) & 15] ); (*arr)=(T*)(*mem); (*mem)=((*arr)+x); } inline void rd(int &x){ int k; int m=0; x=0; for(;;){ k = getchar_unlocked(); if(k=='-'){ m=1; break; } if('0'<=k&&k<='9'){ x=k-'0'; break; } } for(;;){ k = getchar_unlocked(); if(k<'0'||k>'9'){ break; } x=x*10+k-'0'; } if(m){ x=-x; } } inline void rd(char &c){ int i; for(;;){ i = getchar_unlocked(); if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){ break; } } c = i; } inline int rd(char c[]){ int i; int sz = 0; for(;;){ i = getchar_unlocked(); if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){ break; } } c[sz++] = i; for(;;){ i = getchar_unlocked(); if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){ break; } c[sz++] = i; } c[sz]='\0'; return sz; } inline void wt_L(char a){ putchar_unlocked(a); } inline void wt_L(int x){ int s=0; int m=0; char f[10]; if(x<0){ m=1; x=-x; } while(x){ f[s++]=x%10; x/=10; } if(!s){ f[s++]=0; } if(m){ putchar_unlocked('-'); } while(s--){ putchar_unlocked(f[s]+'0'); } } template <class T> struct DijkstraHeap{ int *hp; int *place; int size; char *visited; T *val; void malloc(int N){ hp = (int*)std::malloc(N*sizeof(int)); place = (int*)std::malloc(N*sizeof(int)); visited = (char*)std::malloc(N*sizeof(char)); val = (T*)std::malloc(N*sizeof(T)); } void free(){ std::free(hp); std::free(place); std::free(visited); std::free(val); } void walloc(int N, void **mem=&wmem){ walloc1d(&hp, N, mem); walloc1d(&place, N, mem); walloc1d(&visited, N, mem); walloc1d(&val, N, mem); } void init(int N){ int i; size = 0; for(i=(0);i<(N);i++){ place[i]=-1; } for(i=(0);i<(N);i++){ visited[i]=0; } } void up(int n){ int m; while(n){ m=(n-1)/2; if(val[hp[m]]<=val[hp[n]]){ break; } swap(hp[m],hp[n]); swap(place[hp[m]],place[hp[n]]); n=m; } } void down(int n){ int m; for(;;){ m=2*n+1; if(m>=size){ break; } if(m+1<size&&val[hp[m]]>val[hp[m+1]]){ m++; } if(val[hp[m]]>=val[hp[n]]){ break; } swap(hp[m],hp[n]); swap(place[hp[m]],place[hp[n]]); n=m; } } void change(int n, T v){ if(visited[n]||(place[n]>=0&&val[n]<=v)){ return; } val[n]=v; if(place[n]==-1){ place[n]=size; hp[size++]=n; up(place[n]); } else{ up(place[n]); } } int pop(void){ int res=hp[0]; place[res]=-1; size--; if(size){ hp[0]=hp[size]; place[hp[0]]=0; down(0); } visited[res]=1; return res; } } ; struct dimcomp2{ int B; dimcomp2(){ } dimcomp2(int b){ B = b; } dimcomp2(int a, int b){ B = b; } inline void set(int b){ B = b; } inline void set(int a, int b){ B = b; } inline int mask(int a, int b){ return a * B + b; } inline int operator()(int a, int b){ return a * B + b; } inline void para(int mask, int &a, int &b){ a = mask / B; b = mask % B; } inline void operator()(int mask, int &a, int &b){ a = mask / B; b = mask % B; } } ; int X; int Y; char A[2000][2002]; int main(){ wmem = memarr; int k; int sx; int sy; int nx; int ny; int res; dimcomp2 c; DijkstraHeap<int> hp; int dx[2] = {1,0}; int dy[2] = {0,1}; rd(X); rd(Y); { int Lj4PdHRW; for(Lj4PdHRW=(0);Lj4PdHRW<(X);Lj4PdHRW++){ rd(A[Lj4PdHRW]); } } c.set(X,Y); hp.malloc(X*Y); hp.init(X*Y); hp.change(0,0); while(hp.size){ int d; c(hp.pop(), sx, sy); for(d=(0);d<(2);d++){ nx = sx + dx[d]; ny = sy + dy[d]; if(nx < 0 || ny < 0 || nx >= X || ny >= Y){ continue; } if(A[nx][ny]=='k'){ hp.change(c(nx,ny), hp.val[c(sx,sy)] +nx+ny+1); } else{ hp.change(c(nx,ny), hp.val[c(sx,sy)] +1); } } } res = hp.val[c(X-1,Y-1)]; wt_L(res); wt_L('\n'); return 0; } // cLay varsion 20200112-1 // --- original code --- // int X, Y; // char A[2000][2002]; // // { // int k, sx, sy, nx, ny, res; // dimcomp2 c; // DijkstraHeap<int> hp; // int dx[2] = {1,0}; // int dy[2] = {0,1}; // rd(X,Y,A(X)); // c.set(X,Y); // hp.malloc(X*Y); // hp.init(X*Y); // hp.change(0,0); // while(hp.size){ // c(hp.pop(), sx, sy); // rep(d,2){ // nx = sx + dx[d]; // ny = sy + dy[d]; // if(nx < 0 || ny < 0 || nx >= X || ny >= Y) continue; // hp.change(c(nx,ny), hp.val[c(sx,sy)] + if[A[nx][ny]=='k', nx+ny+1, 1]); // } // } // res = hp.val[c(X-1,Y-1)]; // wt(res); // }