#20294: RE (SIGSEGV)


089487 (089487)

學校 : 國立臺灣師範大學附屬高級中學
編號 : 82069
來源 : [140.112.150.137]
最後登入時間 :
2024-10-03 16:28:37
a597. 祖靈被榨乾了!!!!!!!! -- 成為祖靈的祖靈 | From: [111.71.52.63] | 發表日期 : 2019-12-25 20:33

#include<bits/stdc++.h>
using namespace std;
int main()
{
int t,t2;
while(cin>>t>>t2)
{
int length=-1;
char c[t][t2];
int l[t][t2];
memset(l,0,sizeof(l));
vector< pair<int,int> > v;
for(int i=0;i<t;i++)
{
for(int j=0;j<t;j++)
{
cin>>c[i][j];
if(c[i][j]=='J') v.push_back(pair<int,int>(i,j));
}
}
int num=0;
//cout<<v.size()<<" ";
while(!v.empty())
{
int n=0;
queue<int> x;
queue<int> y;
x.push(v[0].second);
y.push(v[0].first);
l[v[0].first][v[0].second]=1;
//v.pop_back();
while(!x.empty())
{
//for(auto i=v.begin();i!=v.end();++i) cout<<i->first<<" "<<i->second<<"\n";
if(x.front()-1>=0)
{
int x2=x.front()-1;
int y2=y.front();
if(c[y2][x2]=='J'&&!l[y2][x2])
{
l[y2][x2]=1;
x.push(x2);
y.push(y2);
}
}
if(x.front()+1<t2)
{
int x2=x.front()+1;
int y2=y.front();
if(c[y2][x2]=='J'&&!l[y2][x2])
{
l[y2][x2]=1;
x.push(x2);
y.push(y2);
//auto it=find(v.begin(),v.end(),pair<int,int>(y2,x2));
//if(it!=v.end())v.erase(it) ;
//c[y2][x2]='X';
}
}
if(y.front()-1>=0)
{
int x2=x.front();
int y2=y.front()-1;
if(c[y2][x2]=='J'&&!l[y2][x2])
{
l[y2][x2]=1;
x.push(x2);
y.push(y2);
//auto it=find(v.begin(),v.end(),pair<int,int>(y2,x2));
//if(it!=v.end())v.erase(it) ;
//c[y2][x2]='X';
}
}
if(y.front()+1<t)
{
int x2=x.front();
int y2=y.front()+1;
if(c[y2][x2]=='J'&&!l[y2][x2])
{
l[y2][x2]=1;
x.push(x2);
y.push(y2);

//c[y2][x2]='X';
}
}
auto it=find(v.begin(),v.end(),pair<int,int>(y.front(),x.front()));
if(it!=v.end()) v.erase(it) ;
//cout<<"x.front"<<x.front()<<"y.front()"<<y.front()<<"\n";
x.pop();
y.pop();
n++;

}
length=max(length,n);
/*for(int i=0;i<t;i++)
{
for(int j=0;j<t2;j++) cout<<c[i][j];
cout<<"\n";
}
cout<<v.size()<<" ";*/
//cout<<"num";
num++;
}
cout<<num<<" "<<length<<"\n";
}
}

 
#20296: Re:RE (SIGSEGV)


089487 (089487)

學校 : 國立臺灣師範大學附屬高級中學
編號 : 82069
來源 : [140.112.150.137]
最後登入時間 :
2024-10-03 16:28:37
a597. 祖靈被榨乾了!!!!!!!! -- 成為祖靈的祖靈 | From: [111.71.52.63] | 發表日期 : 2019-12-25 21:05

#include<bits/stdc++.h>
using namespace std;
int main()
{
int t,t2;
while(cin>>t>>t2)
{
int length=-1;
char c[t][t2];
int l[t][t2];
memset(l,0,sizeof(l));
vector< pair<int,int> > v;
for(int i=0;i<t;i++)
{
for(int j=0;j<t;j++)
{
cin>>c[i][j];
if(c[i][j]=='J') v.push_back(pair<int,int>(i,j));
}
}
int num=0;
//cout<<v.size()<<" ";
while(!v.empty())
{
int n=0;
queue x;
queue y;
x.push(v[0].second);
y.push(v[0].first);
l[v[0].first][v[0].second]=1;
//v.pop_back();
while(!x.empty())
{
//for(auto i=v.begin();i!=v.end();++i) cout<first<<" "<second<<"\n";
if(x.front()-1>=0)
{
int x2=x.front()-1;
int y2=y.front();
if(c[y2][x2]=='J'&&!l[y2][x2])
{
l[y2][x2]=1;
x.push(x2);
y.push(y2);
}
}
if(x.front()+1<t2)
{
int x2=x.front()+1;
int y2=y.front();
if(c[y2][x2]=='J'&&!l[y2][x2])
{
l[y2][x2]=1;
x.push(x2);
y.push(y2);
//auto it=find(v.begin(),v.end(),pair<int,int>(y2,x2));
//if(it!=v.end())v.erase(it) ;
//c[y2][x2]='X';
}
}
if(y.front()-1>=0)
{
int x2=x.front();
int y2=y.front()-1;
if(c[y2][x2]=='J'&&!l[y2][x2])
{
l[y2][x2]=1;
x.push(x2);
y.push(y2);
//auto it=find(v.begin(),v.end(),pair<int,int>(y2,x2));
//if(it!=v.end())v.erase(it) ;
//c[y2][x2]='X';
}
}
if(y.front()+1<t)
{
int x2=x.front();
int y2=y.front()+1;
if(c[y2][x2]=='J'&&!l[y2][x2])
{
l[y2][x2]=1;
x.push(x2);
y.push(y2);

//c[y2][x2]='X';
}
}
auto it=find(v.begin(),v.end(),pair<int,int>(y.front(),x.front()));
if(it!=v.end()) v.erase(it) ;
//cout<<"x.front"<<x.front()<<"y.front()"<<y.front()<<"\n";
x.pop();
y.pop();
n++;

}
length=max(length,n);
/*for(int i=0;i<t;i++)
{
for(int j=0;j<t2;j++) cout<<c[i][j];
cout<<"\n";
}
cout<<v.size()<<" ";*/
//cout<<"num";
num++;
}
cout<<num<<" "<<length<<"\n";
}
}

沒事了,原來當m,n=500時陣列就會爆掉


 
ZeroJudge Forum