fork download
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define ll long long
  6. #define ini(arr, val) memset(arr, (val), sizeof(arr))
  7. #define loop(i,n) for(ll i=0; i<n; i++)
  8. #define loop1(i,n) for(ll i=1; i<=n; i++)
  9.  
  10. #define all(a) (a).begin(),(a).end()
  11. #define exist(s,e) (s.find(e)!=s.end())
  12. #define dbg(x) cout << #x << " = " << x << endl
  13. #define pt(x) cout<<x<<"\n"
  14. #define pts(x) cout<<x<<" "
  15.  
  16. #define mp make_pair
  17. #define pb push_back
  18. #define F first
  19. #define S second
  20.  
  21.  
  22. #define inf (int)1e9
  23. #define infll 1e18
  24. #define eps 1e-9
  25. #define PI 3.1415926535897932384626433832795
  26. #define mod 1000000007
  27.  
  28.  
  29. #define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  30. #define test int t; cin>>t; while(t--)
  31.  
  32. typedef pair<int, int> pii;
  33. typedef vector<int> vi;
  34. typedef vector<string> vs;
  35. typedef vector<pii> vpii;
  36. typedef vector<vi> vvi;
  37. typedef map<int,int> mii;
  38. typedef set<int> si;
  39.  
  40. typedef pair<ll, ll> pll;
  41. typedef vector<ll> vl;
  42. typedef vector<string> vs;
  43. typedef vector<pll> vpll;
  44. typedef vector<vl> vvl;
  45. typedef map<ll,ll> mll;
  46. typedef set<ll> sl;
  47.  
  48.  
  49. int dirx[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
  50. int diry[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
  51.  
  52.  
  53.  
  54. //===========================DEBUG======================//
  55. #define XOX 1
  56. vector<string> vec_splitter(string s) {
  57. s += ',';
  58. vector<string> res;
  59. while(!s.empty()) {
  60. res.push_back(s.substr(0, s.find(',')));
  61. s = s.substr(s.find(',') + 1);
  62. }
  63. return res;
  64. }
  65. void debug_out(
  66. vector<string> __attribute__ ((unused)) args,
  67. __attribute__ ((unused)) int idx,
  68. __attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
  69. template <typename Head, typename... Tail>
  70. void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
  71. if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
  72. stringstream ss; ss << H;
  73. cerr << args[idx] << " = " << ss.str();
  74. debug_out(args, idx + 1, LINE_NUM, T...);
  75. }
  76. #ifdef XOX
  77. #define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
  78. #else
  79. #define debug(...) 42
  80. #endif
  81.  
  82. //================================================================//
  83.  
  84.  
  85.  
  86. //////////////////////////////////////////////////////////////////////////////////////////
  87. // main starts
  88. //////////////////////////////////////////////////////////////////////////////////////////
  89. int const lmt=1e5+5;
  90. string s[100];
  91. int adj[26][26];
  92. stack<int> st;
  93. int vis[26];
  94. int pre[26];
  95. bool ok;
  96. void dfs(int p){
  97. // debug(char(p+'A'));
  98. // if(!ok)return;
  99. vis[p]=1;
  100. for(int i=0; i<26; i++){
  101. if(!pre[i] || !adj[p][i])continue;
  102.  
  103. if(vis[i]==0)dfs(i);
  104. else if(vis[i]==1)ok=0;
  105. }
  106. vis[p]=2;
  107. st.push(p);
  108. }
  109.  
  110. int main(){
  111. // #ifndef ONLINE_JUDGE
  112. // freopen("../input.txt", "r", stdin);
  113. // freopen("../output.txt", "w", stdout);
  114. // #endif
  115. fast
  116. int T=1;
  117. test{
  118.  
  119. ll r,c;
  120. cin>>r>>c;
  121.  
  122. loop(i,r){
  123. cin>>s[i];
  124. }
  125. ini(adj,0);
  126. ini(vis,0);
  127. ok=1;
  128. ini(pre,0);
  129. while(st.size()){st.pop();}
  130.  
  131. for(int j=0; j<c; j++){
  132. for(int i=0; i<r-1; i++){
  133. int a = s[i+1][j]-'A';
  134. int b = s[i][j]-'A';
  135.  
  136. pre[a]=1;
  137. pre[b]=1;
  138. if(a==b)continue;
  139. adj[a][b]=1;
  140. }
  141. }
  142. for(int i=0; i<26; i++) if(pre[i] && !vis[i]){
  143. dfs(i);
  144. // debug(char(i+'A'));
  145. }
  146. cout<< "Case #" << T++ << ": ";
  147.  
  148. if(!ok)pts("-1");
  149. else while(!st.empty()){
  150. cout<<char(st.top() + 'A');
  151. st.pop();
  152. }
  153.  
  154. cout<<"\n";
  155. }
  156. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:1: error: illegal character: '#'
#include<bits/stdc++.h>
^
Main.java:1: error: class, interface, or enum expected
#include<bits/stdc++.h>
        ^
Main.java:5: error: illegal character: '#'
#define ll long long
^
Main.java:5: error: class, interface, or enum expected
#define ll long long
        ^
Main.java:6: error: illegal character: '#'
#define ini(arr, val) memset(arr, (val), sizeof(arr))
^
Main.java:7: error: illegal character: '#'
#define loop(i,n)  for(ll i=0; i<n; i++)
^
Main.java:7: error: class, interface, or enum expected
#define loop(i,n)  for(ll i=0; i<n; i++)
                               ^
Main.java:7: error: class, interface, or enum expected
#define loop(i,n)  for(ll i=0; i<n; i++)
                                    ^
Main.java:8: error: illegal character: '#'
#define loop1(i,n)  for(ll i=1; i<=n; i++)
^
Main.java:8: error: class, interface, or enum expected
#define loop1(i,n)  for(ll i=1; i<=n; i++)
                                ^
Main.java:8: error: class, interface, or enum expected
#define loop1(i,n)  for(ll i=1; i<=n; i++)
                                      ^
Main.java:10: error: illegal character: '#'
#define all(a)      (a).begin(),(a).end()
^
Main.java:11: error: illegal character: '#'
#define exist(s,e)  (s.find(e)!=s.end())
^
Main.java:12: error: illegal character: '#'
#define dbg(x)  cout << #x << " = " << x << endl
^
Main.java:12: error: illegal character: '#'
#define dbg(x)  cout << #x << " = " << x << endl
                        ^
Main.java:13: error: illegal character: '#'
#define pt(x) cout<<x<<"\n"
^
Main.java:14: error: illegal character: '#'
#define pts(x) cout<<x<<" "
^
Main.java:16: error: illegal character: '#'
#define mp make_pair
^
Main.java:17: error: illegal character: '#'
#define pb push_back
^
Main.java:18: error: illegal character: '#'
#define F first
^
Main.java:19: error: illegal character: '#'
#define S second
^
Main.java:22: error: illegal character: '#'
#define inf (int)1e9
^
Main.java:23: error: illegal character: '#'
#define infll 1e18
^
Main.java:24: error: illegal character: '#'
#define eps 1e-9
^
Main.java:25: error: illegal character: '#'
#define PI 3.1415926535897932384626433832795
^
Main.java:26: error: illegal character: '#'
#define mod 1000000007
^
Main.java:29: error: illegal character: '#'
#define fast    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
^
Main.java:29: error: class, interface, or enum expected
#define fast    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
                                             ^
Main.java:29: error: class, interface, or enum expected
#define fast    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
                                                        ^
Main.java:30: error: illegal character: '#'
#define test   int t; cin>>t; while(t--)
^
Main.java:30: error: class, interface, or enum expected
#define test   int t; cin>>t; while(t--)
        ^
Main.java:30: error: class, interface, or enum expected
#define test   int t; cin>>t; while(t--)
                      ^
Main.java:30: error: class, interface, or enum expected
#define test   int t; cin>>t; while(t--)
                              ^
Main.java:33: error: class, interface, or enum expected
typedef vector<int> vi;
^
Main.java:34: error: class, interface, or enum expected
typedef vector<string> vs;
^
Main.java:35: error: class, interface, or enum expected
typedef vector<pii> vpii;
^
Main.java:36: error: class, interface, or enum expected
typedef vector<vi> vvi;
^
Main.java:37: error: class, interface, or enum expected
typedef map<int,int> mii;
^
Main.java:38: error: class, interface, or enum expected
typedef set<int> si;
^
Main.java:40: error: class, interface, or enum expected
typedef pair<ll, ll> pll;
^
Main.java:41: error: class, interface, or enum expected
typedef vector<ll> vl;
^
Main.java:42: error: class, interface, or enum expected
typedef vector<string> vs;
^
Main.java:43: error: class, interface, or enum expected
typedef vector<pll> vpll;
^
Main.java:44: error: class, interface, or enum expected
typedef vector<vl> vvl;
^
Main.java:45: error: class, interface, or enum expected
typedef map<ll,ll> mll;
^
Main.java:46: error: class, interface, or enum expected
typedef set<ll> sl;
^
Main.java:49: error: class, interface, or enum expected
int dirx[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
^
Main.java:50: error: class, interface, or enum expected
int diry[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
^
Main.java:55: error: illegal character: '#'
#define XOX 1
^
Main.java:55: error: class, interface, or enum expected
#define XOX 1
        ^
Main.java:58: error: class, interface, or enum expected
    vector<string> res;
    ^
Main.java:59: error: class, interface, or enum expected
    while(!s.empty()) {
    ^
Main.java:61: error: class, interface, or enum expected
        s = s.substr(s.find(',') + 1);
        ^
Main.java:62: error: class, interface, or enum expected
    }
    ^
Main.java:64: error: class, interface, or enum expected
}
^
Main.java:68: error: class, interface, or enum expected
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
                                                       ^
Main.java:71: error: class, interface, or enum expected
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
                              ^
Main.java:72: error: class, interface, or enum expected
    stringstream ss; ss << H;
    ^
Main.java:72: error: class, interface, or enum expected
    stringstream ss; ss << H;
                     ^
Main.java:73: error: class, interface, or enum expected
    cerr << args[idx] << " = " << ss.str();
    ^
Main.java:74: error: class, interface, or enum expected
    debug_out(args, idx + 1, LINE_NUM, T...);
    ^
Main.java:75: error: class, interface, or enum expected
}
^
Main.java:76: error: illegal character: '#'
#ifdef XOX
^
Main.java:77: error: illegal character: '#'
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
^
Main.java:77: error: illegal character: '#'
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
                                          ^
Main.java:78: error: illegal character: '#'
#else
^
Main.java:79: error: illegal character: '#'
#define debug(...) 42
^
Main.java:80: error: illegal character: '#'
#endif
^
Main.java:90: error: class, interface, or enum expected
string s[100];
^
Main.java:91: error: class, interface, or enum expected
int adj[26][26];
^
Main.java:92: error: class, interface, or enum expected
stack<int> st;
^
Main.java:93: error: class, interface, or enum expected
int vis[26];
^
Main.java:94: error: class, interface, or enum expected
int pre[26];
^
Main.java:95: error: class, interface, or enum expected
bool ok;
^
Main.java:96: error: class, interface, or enum expected
void dfs(int p){
^
Main.java:100: error: class, interface, or enum expected
    for(int i=0; i<26; i++){
    ^
Main.java:100: error: class, interface, or enum expected
    for(int i=0; i<26; i++){
                 ^
Main.java:100: error: class, interface, or enum expected
    for(int i=0; i<26; i++){
                       ^
Main.java:103: error: class, interface, or enum expected
        if(vis[i]==0)dfs(i);
        ^
Main.java:104: error: class, interface, or enum expected
        else if(vis[i]==1)ok=0;
        ^
Main.java:105: error: class, interface, or enum expected
    }
    ^
Main.java:107: error: class, interface, or enum expected
    st.push(p);
    ^
Main.java:108: error: class, interface, or enum expected
}
^
Main.java:117: error: class, interface, or enum expected
    test{
    ^
Main.java:120: error: class, interface, or enum expected
        cin>>r>>c;
        ^
Main.java:122: error: class, interface, or enum expected
        loop(i,r){
        ^
Main.java:124: error: class, interface, or enum expected
        }
        ^
Main.java:126: error: class, interface, or enum expected
        ini(vis,0);
        ^
Main.java:127: error: class, interface, or enum expected
        ok=1;
        ^
Main.java:128: error: class, interface, or enum expected
        ini(pre,0);
        ^
Main.java:129: error: class, interface, or enum expected
        while(st.size()){st.pop();}
        ^
Main.java:129: error: class, interface, or enum expected
        while(st.size()){st.pop();}
                                  ^
Main.java:131: error: class, interface, or enum expected
        for(int j=0; j<c; j++){
                     ^
Main.java:131: error: class, interface, or enum expected
        for(int j=0; j<c; j++){
                          ^
Main.java:132: error: class, interface, or enum expected
            for(int i=0; i<r-1; i++){
                         ^
Main.java:132: error: class, interface, or enum expected
            for(int i=0; i<r-1; i++){
                                ^
Main.java:134: error: class, interface, or enum expected
                int b = s[i][j]-'A';
                ^
Main.java:136: error: class, interface, or enum expected
                pre[a]=1;
                ^
Main.java:137: error: class, interface, or enum expected
                pre[b]=1;
                ^
Main.java:138: error: class, interface, or enum expected
                if(a==b)continue;
                ^
100 errors
stdout
Standard output is empty