Submission #1092531

# Submission time Handle Problem Language Result Execution time Memory
1092531 2024-09-24T10:26:52 Z vjudge1 Cezar (COCI16_cezar) C++17
20 / 100
1 ms 440 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)) break;
				if(a[h]==b[h]){
					if(h==SZ(a)&&SZ(a)<SZ(b)){
						cout<<"NE\n";
						return 0;
					}
					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:89:2: note: in expansion of macro 'forn'
   89 |  forn(i,0,SZ(dicc)) cout<<dicc[i]; cout<<'\n';
      |  ^~~~
cezar.cpp:89:36: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   89 |  forn(i,0,SZ(dicc)) cout<<dicc[i]; cout<<'\n';
      |                                    ^~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 440 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 436 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -