fork download
  1. //http://w...content-available-to-author-only...o.org/index.php?page=viewproblem2&cpid=1132
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4.  
  5. int K, N;
  6. vector<vector<string>>answer;
  7. vector<vector<string>>paper;
  8. map<string, int> names;
  9.  
  10. void testing(vector<vector<string>>a) {//prints out a vector<vector<string>>
  11. for (int i = 0; i < a.size(); i++) {
  12. for (int j = 0; j < a[i].size(); j++) {
  13. cout << a[i][j];
  14. }
  15. cout << endl;
  16. }
  17. }
  18.  
  19. void update(vector<string>b, int index) { //updates the answer vector based on the paper and index
  20. for (int i = 0; i < index; i++) {
  21. for (int j = index; j < N; j++) {
  22. answer[names[b[j]]][names[b[i]]] = "1";
  23. answer[names[b[i]]][names[b[j]]] = "0";
  24. }
  25. }
  26. }
  27.  
  28. int main(void) {
  29.  
  30. cin >> K >> N;
  31.  
  32. //dictionary for names for quick conversion from name to integer
  33. for (int i = 0; i < N; i++) {
  34. string temp;
  35. cin >> temp;
  36. names.insert({ temp, i });
  37. }
  38. //inputs the names for each paper
  39. for (int i = 0; i < K; i++) {
  40. vector<string>temp;
  41. for (int j = 0; j < N; j++) {
  42. string temps;
  43. cin >> temps;
  44. temp.push_back(temps);
  45. }
  46. paper.push_back(temp);
  47. }
  48. //initialises the answer matrix with all ? except for the diagonal (where values should be B)
  49. for (int i = 0; i < N; i++) {
  50. vector<string>temp;
  51. for (int j = 0; j < N; j++) {
  52. if (i != j) {
  53. temp.push_back("?");
  54. }
  55. else {
  56. temp.push_back("B");
  57. }
  58. }
  59. answer.push_back(temp);
  60. }
  61.  
  62. for (int i = 0; i < K; i++) {//for each paper
  63. for (int j = 1; j < N; j++) {//for each name
  64. cout << paper[i][j].compare(paper[i][j - 1]) << endl;
  65. if (paper[i][j].compare(paper[i][j - 1]) == -1) {
  66. cout << "FOUND " << i << " " << j << endl;
  67. update(paper[i], j);
  68. }
  69. }
  70. }
  71. testing(answer);
  72. //The output from my 2019 Visual Studio Code is fine, it passes all test cases i tried from the USACO website
  73. //But when I submit it to the USACO website with C++17 chosen, it prints out the initial answer matrix
  74. //which is the one on line 49
  75.  
  76. return 0;
  77. }
Success #stdin #stdout 0s 5496KB
stdin
1 3
dean elsie mildred
elsie mildred dean
stdout
8
-9
B??
?B?
??B