Problem Info
Acowdemia II USACO
My Work
//http://www.usaco.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
if (paper[i][j].compare(paper[i][j - 1]) == -1) {
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;
}
Add explanation of code here
What I’ve Tried
I’ve tried to change the datatypes of the answer matrix and the other data associated with it from string to char, but it still didn’t work.
Question
I don’t understand why my code is failing once I submitted it to the USACO website, but not locally.
Checklist
See How to ask for help on a problem for more information.
- Include a link to the problem
- Format your post (especially code blocks)
- Include what you’ve tried so far
- Add comments to your code
- Read the debugging module