Блог пользователя someone_lunatic_lyk_hell

Автор someone_lunatic_lyk_hell, история, 2 года назад, По-английски

Hi All, In the Spoj Problem ABCPATH- ABC Path, I am not able to figure out: why my code is getting runtime error?

Here is the link to problem: ABC PATHhttps://www.spoj.com/problems/ABCPATH/

Here is my code: ~~~~~

pragma GCC optimize("O3,unroll-loops")

pragma GCC optimize(3, "Ofast", "inline")

include<bits/stdc++.h>

using namespace std; using namespace chrono;

define endl "\n"

define _USE_MATH_DEFINES

include

ifndef M_PI

#define M_PI 3.14159265358979323846

endif

define int long long int

define pb push_back

define mk make_pair

define ppb pop_back

define pf push_front

define ppf pop_front

define all(x) (x).begin(),(x).end()

define ub upper_bound

define lb lower_bound

define uniq(v) (v).erase(unique(all(v)),(v).end())

define sz(x) (int)((x).size())

define fr first

define sc second

define pii pair<int,int>

define rep(i,a,b) for(int i=a;i<b;i++)

define mem1(a) memset(a,-1,sizeof(a))

define mem0(a) memset(a,0,sizeof(a))

define ppc __builtin_popcount

define ppcll __builtin_popcountll

int const N=2*1e5+10; //int const INF=1e18; int mod=1e9+7; int mod1=998244353; const int INF=1e4;

define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

int r,c; int dx[]={1,1,-1,-1,0,0,1,-1}; int dy[]={1,-1,1,-1,1,-1,0,0}; bool vis[60][60]; vector<vector>grid; int mx=0;

bool is_valid(int i, int j){ return (i>=0 && j>=0 && i<r && j<c); }

void dfs(int i, int j, int l){ if(vis[i][j])return;

vis[i][j]=1; mx=max(mx,l);

rep(k,0,8){ int x=i+dx[k]; int y=j+dy[k]; if(vis[x][y] || !is_valid(x,y))continue;

if(grid[x][y]-grid[i][j]==1)
  dfs(x,y,l+1);

} }

void solve(){ int k=0; while(cin>>r>>c){ if(!r && !c)break;

grid.resize(r,vector<char>(c));
// vis.resize(r,vector<bool>(c,false));
// cout<<grid.size()<<" "<<grid[0].size()<<endl;
rep(i,0,r){
  string s; cin>>s;
  rep(j,0,c){
    grid[i][j]=s[j];
   // cout<<vis[i][j]<<" ";
  }
 // cout<<endl;
}
memset(vis,false,sizeof(vis));

// mx=0;

rep(i,0,r){
  rep(j,0,c){
    if(grid[i][j]=='A')dfs(i,j,1);
  }
}

cout<<"Case "<<++k<<": "<<mx<<endl;
mx=0;

} return; }

signed main(){ #ifndef ONLINE_JUDGE freopen("INPUT1.txt","r",stdin); freopen("out1.txt","w",stdout); #endif

fastio();
auto start1 = high_resolution_clock::now();
int t=1;
//cin>>t;

// precompute();

//fill_dp();
while(t--){
  solve();
}
auto stop1 = high_resolution_clock::now();
auto duration = duration_cast<microseconds>(stop1 - start1);
#ifndef ONLINE_JUDGE
cout << "Time: " << duration . count() / 1000 <<"ms"<<endl;
#endif

return 0; }

~~~~~

`

  • Проголосовать: нравится
  • -18
  • Проголосовать: не нравится

»
2 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

no help