結果
問題 | No.596 郵便配達 |
ユーザー | 👑 kmjp |
提出日時 | 2017-11-11 03:17:18 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 1,577 ms / 5,000 ms |
コード長 | 1,937 bytes |
コンパイル時間 | 1,541 ms |
コンパイル使用メモリ | 147,616 KB |
実行使用メモリ | 58,580 KB |
最終ジャッジ日時 | 2023-08-16 06:23:27 |
合計ジャッジ時間 | 9,076 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge15 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 228 ms
13,568 KB |
testcase_01 | AC | 231 ms
13,864 KB |
testcase_02 | AC | 2 ms
5,488 KB |
testcase_03 | AC | 2 ms
5,440 KB |
testcase_04 | AC | 490 ms
23,804 KB |
testcase_05 | AC | 1,577 ms
58,284 KB |
testcase_06 | AC | 100 ms
9,208 KB |
testcase_07 | AC | 2 ms
5,416 KB |
testcase_08 | AC | 303 ms
13,600 KB |
testcase_09 | AC | 2 ms
5,380 KB |
testcase_10 | AC | 2 ms
5,484 KB |
testcase_11 | AC | 2 ms
5,384 KB |
testcase_12 | AC | 1 ms
5,636 KB |
testcase_13 | AC | 2 ms
5,616 KB |
testcase_14 | AC | 2 ms
5,428 KB |
testcase_15 | AC | 2 ms
5,464 KB |
testcase_16 | AC | 2 ms
5,392 KB |
testcase_17 | AC | 2 ms
5,428 KB |
testcase_18 | AC | 2 ms
5,560 KB |
testcase_19 | AC | 2 ms
5,428 KB |
testcase_20 | AC | 969 ms
58,336 KB |
testcase_21 | AC | 976 ms
58,360 KB |
testcase_22 | AC | 970 ms
58,580 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef signed long long ll; #undef _P #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) //------------------------------------------------------- int N,M; int L[7070707], R[7070707]; int add[7]={0,1,1,2,3,3,0}; int lef[7]={0,0,1,1,1,1,0}; int rig[7]={0,1,0,1,1,1,0}; // before, ->, <- , <-> , -><-->, <-->-<, done // 1-non 2-start 3-end int mat[7][7]={ {1,2,3,1,2,3,1}, {0,1,0,3,1,0,3}, {0,0,1,2,0,1,2}, {0,2,3,1,0,0,1}, {0,1,0,0,1,0,3}, {0,0,1,0,0,1,2}, {0,0,0,0,0,0,1}, }; int from[7][2][2]; int to[7][2][2]; void solve() { int i,j,k,l,r,x,y; string s; cin>>N>>M; int miX=N,maX=0; FOR(i,M) { int X,miy,may; cin>>X>>x; miy=may=X; while(x--) { cin>>y; miy=min(miy,y); may=max(may,y); } L[miy]++; L[X]--; R[X]++; R[may]--; miX=min(miX,miy); maX=max(maX,may); } FOR(i,7) FOR(x,2) FOR(y,2) from[i][x][y]=1<<30; from[0][0][0]=0; FOR(i,N) { FOR(j,7) FOR(x,2) FOR(y,2) to[j][x][y]=1<<30; FOR(y,7) { if(L[i]&&lef[y]==0) continue; if(R[i]&&rig[y]==0) continue; FOR(x,7) if(mat[x][y]) { FOR(j,2) FOR(k,2) { int j2=j+(mat[x][y]==2); int k2=k+(mat[x][y]==3); if(j2<2 && k2<2) to[y][j2][k2]=min(to[y][j2][k2],from[x][j][k]+add[y]); } } } if(i>=miX) to[0][0][0]=1<<30; if(i+1<=maX) to[6][0][0]=to[6][1][1]=1<<30; L[i+1]+=L[i]; R[i+1]+=R[i]; swap(from,to); } cout<<min(from[6][0][0],from[6][1][1])<<endl; } int main(int argc,char** argv){ string s;int i; if(argc==1) ios::sync_with_stdio(false), cin.tie(0); FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin); cout.tie(0); solve(); return 0; }