답안 #1092197

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1092197 2024-09-23T13:49:55 Z vjudge1 Cezar (COCI16_cezar) C++17
40 / 100
1 ms 348 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define pb push_back
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
#define forn(i,a,b) for(int i = a; i < b; i++)

const int MAXN = 100;
const int MAXL = 26;

struct Word{
	string str;
	ll ord;
	Word(ll ord, string str) : ord(ord), str(str) {}
};

bool cmp(const Word &a, const Word &b) {
	if(a.ord<b.ord) return true;
	return false;
}

ll n;
string strs[MAXN];
ll ord[MAXN];

bool menor[MAXL][MAXL];  // menor[i][j] = true -> si i < j

int main(){
	cin>>n;
	forn(i,0,n) cin>>strs[i];
	forn(i,0,n) cin>>ord[i];
	
	vector<Word> sorted;
	forn(i,0,n) sorted.pb(Word(i,strs[ord[i]-1]));
	sort(ALL(sorted),cmp);
	
	forn(i,0,n){
		forn(j,i+1,n){
			string a,b; a = sorted[i].str; b = sorted[j].str;
			//cout<<a<<" "<<b<<'\n';
			forn(h,0,SZ(a)){
				if(h>=SZ(b)){
					cout<<"NE\n";
					return 0;
				}
				if(a[h]==b[h]) continue;
				menor[a[h]-'a'][b[h]-'a']=true;
				//cout<<a[h]<<" "<<b[h]<<'\n';
				if(menor[b[h]-'a'][a[h]-'a']){
					cout<<"NE\n";
					return 0;
				}
				break;
			}
		}
	}
	
	vector<bool> used(MAXL,false);
	vector<char> dicc(MAXL);
	forn(i,0,MAXL){
		bool puede = true;
		forn(j,0,MAXL){
			puede=true;
			if(used[j]) puede = false;
			forn(h,0,MAXL){
				if(menor[h][j]) puede = false;
			}
			if(puede){ dicc[j]=i+'a'; used[j]=true; forn(h,0,MAXL){menor[j][h]=false;} break; }
			else if(!used[j]){
				//cout<<j<<" no pudo en "<<i<<'\n';
			}
		}
		if(!puede){
			cout<<"NE\n";
			return 0;
		}
	}
	
	
	cout<<"DA\n";
	forn(i,0,SZ(dicc)) cout<<dicc[i]; cout<<'\n';
	return 0;
}

Compilation message

cezar.cpp: In constructor 'Word::Word(ll, std::string)':
cezar.cpp:17:5: warning: 'Word::ord' will be initialized after [-Wreorder]
   17 |  ll ord;
      |     ^~~
cezar.cpp:16:9: warning:   'std::string Word::str' [-Wreorder]
   16 |  string str;
      |         ^~~
cezar.cpp:18:2: warning:   when initialized here [-Wreorder]
   18 |  Word(ll ord, string str) : ord(ord), str(str) {}
      |  ^~~~
cezar.cpp: In function 'int main()':
cezar.cpp:10:21: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   10 | #define forn(i,a,b) for(int i = a; i < b; i++)
      |                     ^~~
cezar.cpp:85:2: note: in expansion of macro 'forn'
   85 |  forn(i,0,SZ(dicc)) cout<<dicc[i]; cout<<'\n';
      |  ^~~~
cezar.cpp:85:36: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   85 |  forn(i,0,SZ(dicc)) cout<<dicc[i]; cout<<'\n';
      |                                    ^~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -