diff --git a/CMakeLists.txt b/CMakeLists.txt index ebc1fac..62c0f28 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,8 +2,8 @@ cmake_minimum_required(VERSION 3.15) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) add_compile_options(-Wall) -add_compile_options(-fsanitize=address,pointer-compare,pointer-subtract,undefined -fno-omit-frame-pointer) -add_link_options(-fsanitize=address,pointer-compare,pointer-subtract,undefined -fno-omit-frame-pointer) +# add_compile_options(-fsanitize=address,pointer-compare,pointer-subtract,undefined -fno-omit-frame-pointer) +# add_link_options(-fsanitize=address,pointer-compare,pointer-subtract,undefined -fno-omit-frame-pointer) include_directories(${CMAKE_CURRENT_LIST_DIR}/include) set(CMAKE_CXX_STANDARD 26) diff --git a/src/10/14/P4818.cpp b/src/10/14/P4818.cpp index 8bbd2fa..98ad99f 100644 --- a/src/10/14/P4818.cpp +++ b/src/10/14/P4818.cpp @@ -1,83 +1,109 @@ #include +#include #include #include #include using ll = int64_t; -const ll maxn = 1000+5; -ll n,m; -ll a[maxn][maxn]; -struct D{ - ll x,y,d; - bool is2,ish; -}; -std::deque d; -bool vis[maxn][maxn][4]; -const ll dir[4][2]={ - {1,0}, - {-1,0}, - {0,1}, - {0,-1} -}; +#define sl static inline -int main(){ +const ll maxn = 1005; +ll n, m; +int a[maxn][maxn]; +bool vis[maxn][maxn][4][2]; +int dir[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}; +struct Q { + Q(ll s, ll x, ll y, ll dir, bool is2) : s(s), x(x), y(y), dir(dir), is2(is2) { + } + ll s, x, y, dir; + bool is2; +}; +std::deque q; + +sl bool check(ll x, ll y, ll dir, bool is2) { + if (x < 1 || x > n || y < 1 || y > m) + return false; + if (a[x][y] == 0) + return false; + if (a[x][y] == 3 && !is2) + return false; + + if (a[x][y] == 4) { + return !vis[x][y][dir][false]; + } else { + return !vis[x][y][0][is2]; + } +} + +int main() { std::iostream::sync_with_stdio(false); std::cin.tie(nullptr); - std::cin>>n>>m; - for(ll i=1;i<=n;i++){ - for(ll j=1;j<=m;j++){ - std::cin>>a[i][j]; + std::cin >> n >> m; + for (ll i = 1; i <= n; i++) { + for (ll j = 1; j <= m; j++) { + std::cin >> a[i][j]; } } - d.emplace_back(1,1,0,false); - while (d.size()) { - auto[x,y,dd,is2,ish] = d.front(); - d.pop_front(); - if(ish && a[x][y]==4){ - ll nx = x+dir[dd][0], ny=y+dir[dd][1]; - if(a[nx][ny]==3){ - if(vis[nx][ny][is2])continue; - }else if(a[nx][ny]==4){ - if(vis[nx][ny][dd])continue; - }else if(vis[nx][ny][0])continue; - if(ll na=a[nx][ny];na==0){ + q.emplace_back(0, 1, 1, 0, false); + vis[1][1][0][false] = true; + + while (q.size()) { + auto [s, x, y, dd, is2] = q.front(); + q.pop_front(); + + if (x == n && y == m) { + std::cout << s << "\n"; + return 0; + } + + if (a[x][y] == 4) { + ll nx = x + dir[dd][0], ny = y + dir[dd][1]; + + if (nx < 1 || nx > n || ny < 1 || ny > m) continue; - }else if(na==1){ - d.emplace_back(nx,ny,dd,false,false); - vis[nx][ny][0]=true; - }else if(na==2){ - d.emplace_back(nx,ny,dd,true,false); - vis[nx][ny][0]=true; - }else if(na==3){ + + bool nis2 = (a[nx][ny] == 2); + + if (!check(nx, ny, dd, nis2)) continue; - }else if(na==4){ - d.emplace_back(nx,ny,dd,false,true); - vis[nx][ny][dd]=true; + + if (a[nx][ny] == 4) { + + vis[nx][ny][dd][false] = true; + } else { + + vis[nx][ny][0][nis2] = true; } + + q.emplace_back(s + 1, nx, ny, dd, nis2); continue; } - for(ll i=0;i<4;i++){ - ll nx = x + dir[i][0], ny = y+dir[i][1]; - if(ll na = a[nx][ny];na==0){ + for (ll i = 0; i < 4; i++) { + ll nx = x + dir[i][0], ny = y + dir[i][1]; + + if (nx < 1 || nx > n || ny < 1 || ny > m) continue; - }else if(na==1){ - d.emplace_back(nx,ny,i,false,false); - vis[nx][ny][0]=true; - }else if(na==2){ - d.emplace_back(nx,ny,i,true,false); - vis[nx][ny][0]=true; - }else if(na==3){ - if(is2){ - d.emplace_back(nx,ny,i,true,false); - vis[nx][ny][is2]=true; - } - }else if(na==4){ - d.emplace_back(nx,ny,i,false,true); - vis[nx][ny][i]=true; + + bool nis2 = is2; + if (a[nx][ny] == 2) + nis2 = true; + if (a[nx][ny] == 4) + nis2 = false; + + if (!check(nx, ny, i, nis2)) + continue; + + if (a[nx][ny] == 4) { + vis[nx][ny][i][false] = true; + } else { + vis[nx][ny][0][nis2] = true; } + + q.emplace_back(s + 1, nx, ny, i, nis2); } } + std::cout << "-1\n"; } \ No newline at end of file diff --git a/src/10/14/P6003cal.cpp b/src/10/14/P6003cal.cpp index 8738d38..e748be1 100644 --- a/src/10/14/P6003cal.cpp +++ b/src/10/14/P6003cal.cpp @@ -6,15 +6,15 @@ using ll = int64_t; int main(){ - ll n,k,m; - std::cin>>n>>k>>m; + ll n=100,k=100,m=1; + // std::cin>>n>>k>>m; for(ll x=25;x<=25;x++){ ll g=0; for(ll i=1;i<=k;i++){ ll y=(n-g)/x; y=std::max(y,m); g+=y; - printf("i=%lld, g=%lld\n",i,g); + printf("(n-g)=%lld, y=%lld, x=%lld\n",n-g,y,x); } printf("-- x=%lld, g=%lld\n\n",x,g); } diff --git a/src/10/16/P6003.cpp b/src/10/16/P6003.cpp new file mode 100644 index 0000000..c460859 --- /dev/null +++ b/src/10/16/P6003.cpp @@ -0,0 +1,38 @@ +#include +#include +#include +#include +using ll = int64_t; +#define sl static inline +ll n,k,m; + +sl bool check(ll x){ + ll g=0; + for(ll i=1;i<=k;i++){ + ll y=(n-g)/x; + if(y=n; +} + +int main(){ + std::iostream::sync_with_stdio(false); + std::cin.tie(nullptr); + + std::cin>>n>>k>>m; + ll l=1,r=n,ans=0,mid; + while(l