//http://w...content-available-to-author-only...o.org/index.php?page=viewproblem2&cpid=1132
#include<bits/stdc++.h>
using namespace std;
int K, N;
vector<vector<string>>answer;
vector<vector<string>>paper;
map<string, int> names;
void testing(vector<vector<string>>a) {//prints out a vector<vector<string>>
for (int i = 0; i < a.size(); i++) {
for (int j = 0; j < a[i].size(); j++) {
cout << a[i][j];
}
cout << endl;
}
}
void update(vector<string>b, int index) { //updates the answer vector based on the paper and index
for (int i = 0; i < index; i++) {
for (int j = index; j < N; j++) {
answer[names[b[j]]][names[b[i]]] = "1";
answer[names[b[i]]][names[b[j]]] = "0";
}
}
}
int main(void) {
cin >> K >> N;
//dictionary for names for quick conversion from name to integer
for (int i = 0; i < N; i++) {
string temp;
cin >> temp;
names.insert({ temp, i });
}
//inputs the names for each paper
for (int i = 0; i < K; i++) {
vector<string>temp;
for (int j = 0; j < N; j++) {
string temps;
cin >> temps;
temp.push_back(temps);
}
paper.push_back(temp);
}
//initialises the answer matrix with all ? except for the diagonal (where values should be B)
for (int i = 0; i < N; i++) {
vector<string>temp;
for (int j = 0; j < N; j++) {
if (i != j) {
temp.push_back("?");
}
else {
temp.push_back("B");
}
}
answer.push_back(temp);
}
for (int i = 0; i < K; i++) {//for each paper
for (int j = 1; j < N; j++) {//for each name
cout << paper[i][j].compare(paper[i][j - 1]) << endl;
if (paper[i][j].compare(paper[i][j - 1]) == -1) {
cout << "FOUND " << i << " " << j << endl;
update(paper[i], j);
}
}
}
testing(answer);
//The output from my 2019 Visual Studio Code is fine, it passes all test cases i tried from the USACO website
//But when I submit it to the USACO website with C++17 chosen, it prints out the initial answer matrix
//which is the one on line 49
return 0;
}