답안 #133422

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
133422 2019-07-20T15:01:09 Z tdwn Cezar (COCI16_cezar) C++17
컴파일 오류
0 ms 0 KB
v    #include <bits/stdc++.h>
    #define ll long long 
    #define pb push_back
    #define mp make_pair
    using namespace std;
    const int maxn = 110;
    string tempstr[maxn];
    string str[maxn];
    int perm[maxn], n;
     
    vector<int>g[30], rg[30];
    int visited[maxn];
    vector<int>order;
     
    bool cycle;
    bool edge[maxn][maxn];
     
    int res[maxn];

    void dfs(int node) {
    	if(visited[node] == 2) return;
    	if(visited[node] == 1) {
    		cycle = true;
    		return;
    	}
     
    	visited[node] = 1;
    	for(int i:g[node]) {
    		if(visited[i] == 0) {
    			dfs(i);
    		}
    		else if(visited[i] == 1) {
    			cycle = true;
    		}
    	}
     
    	visited[node] = 2;
    	order.pb(node);
    }
     
    int main() {
    	cin>>n;
    	for(int i=1;i<=n;i++) {
    		cin>>tempstr[i];
    	}
    	for(int i=1;i<=n;i++) {
    		cin>>perm[i];
    	}
    	for(int i=1;i<=n;i++) {
    		str[i] = tempstr[perm[i]];
    	}
     
    	for(int i=1;i<=n;i++) {
    		for(int j=i+1;j<=n;j++) {
    			if(str[j].length() < str[i].length()) {
    				if(str[i].substr(0, str[j].length()) == str[j]) {
    					cout<<"NE\n";
    					return 0;
    				}
    			}
    		}
    	}
     
    	for(int i=1;i<=n;i++) {
    		for(int j=i+1;j<=n;j++) {
    			for(int k=0;k<min(int(str[i].length()), int(str[j].length()));k++) {
    				if(str[i][k] != str[j][k]) {
    					edge[int(str[i][k]-'a')][int(str[j][k]-'a')] = true;
    					break;
    				}
    			}
    		}
    	}
     
    	for(int i=0;i<26;i++) {
    		for(int j=0;j<26;j++) {
    			if(edge[i][j]) g[i].pb(j);
    		}
    	}
     
    	for(int i=25;i>=0;i--) {
    		if(visited[i] == 0) dfs(i);
    	}
     
    	if(cycle) {
    		cout<<"NE\n";
    		return 0;
    	}
     
    	cout<<"DA\n";
    	//reverse(order.begin(), order.end());
    	for(int i=0;i<order.size();i++) {
    		res[order[i]] = i;
    	}
    	for(int i=0;i<n;i++) {
    		cout<<int(res[i]+'a');
    	}
    }

Compilation message

cezar.cpp:1:6: error: stray '#' in program
 v    #include <bits/stdc++.h>
      ^
cezar.cpp:1:1: error: 'v' does not name a type
 v    #include <bits/stdc++.h>
 ^
cezar.cpp:7:5: error: 'string' does not name a type; did you mean 'struct'?
     string tempstr[maxn];
     ^~~~~~
     struct
cezar.cpp:8:5: error: 'string' does not name a type; did you mean 'struct'?
     string str[maxn];
     ^~~~~~
     struct
cezar.cpp:11:5: error: 'vector' does not name a type
     vector<int>g[30], rg[30];
     ^~~~~~
cezar.cpp:13:5: error: 'vector' does not name a type
     vector<int>order;
     ^~~~~~
cezar.cpp: In function 'void dfs(int)':
cezar.cpp:28:16: error: 'g' was not declared in this scope
      for(int i:g[node]) {
                ^
cezar.cpp:38:6: error: 'order' was not declared in this scope
      order.pb(node);
      ^~~~~
cezar.cpp: In function 'int main()':
cezar.cpp:42:6: error: 'cin' was not declared in this scope
      cin>>n;
      ^~~
cezar.cpp:42:6: note: suggested alternative: 'main'
      cin>>n;
      ^~~
      main
cezar.cpp:44:12: error: 'tempstr' was not declared in this scope
       cin>>tempstr[i];
            ^~~~~~~
cezar.cpp:44:12: note: suggested alternative: 'register'
       cin>>tempstr[i];
            ^~~~~~~
            register
cezar.cpp:50:7: error: 'str' was not declared in this scope
       str[i] = tempstr[perm[i]];
       ^~~
cezar.cpp:50:16: error: 'tempstr' was not declared in this scope
       str[i] = tempstr[perm[i]];
                ^~~~~~~
cezar.cpp:50:16: note: suggested alternative: 'register'
       str[i] = tempstr[perm[i]];
                ^~~~~~~
                register
cezar.cpp:55:11: error: 'str' was not declared in this scope
        if(str[j].length() < str[i].length()) {
           ^~~
cezar.cpp:57:10: error: 'cout' was not declared in this scope
          cout<<"NE\n";
          ^~~~
cezar.cpp:66:30: error: 'str' was not declared in this scope
        for(int k=0;k<min(int(str[i].length()), int(str[j].length()));k++) {
                              ^~~
cezar.cpp:66:22: error: 'min' was not declared in this scope
        for(int k=0;k<min(int(str[i].length()), int(str[j].length()));k++) {
                      ^~~
cezar.cpp:66:22: note: suggested alternative: 'main'
        for(int k=0;k<min(int(str[i].length()), int(str[j].length()));k++) {
                      ^~~
                      main
cezar.cpp:77:23: error: 'g' was not declared in this scope
        if(edge[i][j]) g[i].pb(j);
                       ^
cezar.cpp:86:7: error: 'cout' was not declared in this scope
       cout<<"NE\n";
       ^~~~
cezar.cpp:90:6: error: 'cout' was not declared in this scope
      cout<<"DA\n";
      ^~~~
cezar.cpp:92:20: error: 'order' was not declared in this scope
      for(int i=0;i<order.size();i++) {
                    ^~~~~