Rating changes for last rounds are temporarily rolled back. They will be returned soon. ×

 
 
 
 
General
 
 
# Author Problem Lang Verdict Time Memory Sent Judged  
42441458 Practice:
Salma_Essa
510C - 15 C++14 (GCC 6-32) Time limit exceeded on test 11 2000 ms 160 KB 2018-09-04 00:03:24 2018-09-04 00:03:24
→ Source
#include<bits/stdc++.h>
#define pb push_back
#define ll long long
//#define sz size()
using namespace std;


char a[101][101];
bool imp=0;
int visit[40]; string ans;
map<char,vector<char> >m; 
void dfs(char s,bool t=0)
{ if (visit[s-'a']==1) {imp=1; return;}
if (visit[s-'a']==0) t=1;
  visit[s-'a']=1;
   for(int i=0 ; i<m[s].size(); ++i)
   {
     dfs(m[s][i],0);


   }
visit[s-'a']=2;
if (t) ans+=s;
t=0;
}

int main()
{
    ios::sync_with_stdio(0);ios_base::sync_with_stdio(0);cin.tie(0), cout.tie(0);
  int n;
  cin>>n;
  vector<string>v; string x;
  for(int i=0 ; i<n ; ++i)
  { cin>>a[i];

  }
  for(int i=0 ; i<n-1 ; ++i)
  {
    for(int j=0; a[i][j]&&a[i+1][j] ; ++j)
      {     if (a[i+1][j]==' ') {imp=1; cout<<"Impossible"; return 0 ; }
         if(a[i][j]!=a[i+1][j]) {m[a[i][j]].pb(a[i+1][j]); break; }

      }
  }

for(char i='a'; i<='z'; ++i)
{
    if (!visit[i-'a']) dfs(i);
    if (imp) {cout<<"Impossible"; return 0 ; }
}

reverse(ans.begin(),ans.end());
cout<<ans;
    return 0;
}
?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
Jury's answer
?
Checker comment
?
Diagnostics
?
Click to see test details