1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
| #include <string> #include <cstdio> #include <vector> #include <cstdlib> #include <iostream> #include <fstream> #include <filesystem>
using namespace std;
int sstm(const string &str) { return system(str.c_str()); }
bool do_compile(const string &x) { if(filesystem::exists("D:\\working\\" + x + ".hash.bak")) { sstm("certutil -hashfile D:\\working\\" + x + ".cpp SHA256 > D:\\working\\" + x + ".hash"); if(!sstm("D:\\working\\diff.exe D:\\working\\" + x + ".hash D:\\working\\" + x + ".hash.bak")) { filesystem::remove("D:\\working\\" + x + ".hash"); return true; } if(sstm("g++ -std=c++17 -Ofast -march=native D:\\working\\" + x + ".cpp -o D:\\working\\" + x + ".exe")) { filesystem::remove("D:\\working\\" + x + ".hash"); return false; } filesystem::remove("D:\\working\\" + x + ".hash.bak"); filesystem::rename("D:\\working\\" + x + ".hash", "D:\\working\\" + x + ".hash.bak"); } else { if(sstm("g++ -std=c++17 -Ofast -march=native D:\\working\\" + x + ".cpp -o D:\\working\\" + x + ".exe")) { printf("Failed when compiling %s.cpp.\n", x.c_str()); return false; } sstm("certutil -hashfile D:\\working\\" + x + ".cpp SHA256 > D:\\working\\" + x + ".hash.bak"); } return true; }
int main(int argc, char *argv[]) { if(argc < 2) { printf("ILLEGAL ARGUMENTS\n"); return 1; } vector<string> names; if(argc == 2) names = {argv[1], string(argv[1]) + "-sol"}; else { for(int i=1;i<argc;i++) { names.push_back(argv[i]); } } printf("[log] build diff.cpp\n"); if(!do_compile("diff")) { printf("Failed when compiling diff.cpp.\n"); return 2; } printf("[log] build maker.cpp\n"); if(!do_compile("maker")) { printf("Failed when compiling maker.cpp.\n"); return 4; } printf("[log] build validator.cpp\n"); if(!do_compile("validator")) { printf("Failed when compiling validator.cpp.\n"); return 8; } for(const auto &x : names) { printf("[log] build %s.cpp\n", x.c_str()); if(!do_compile(x)) { printf("Failed when compiling %s.cpp.\n", x.c_str()); return 16; } } do { printf("[log] execute maker.exe\n"); int stat = 0; if(stat = sstm("D:\\working\\maker.exe > D:\\working\\data.in")) { printf("maker returned %d\n", stat); return 32; } printf("[log] execute validator.exe\n"); if(sstm("D:\\working\\validator.exe < D:\\working\\data.in")) { printf("Data invalid.\n"); continue; } for(const auto &x : names) { printf("[log] execute %s.exe\n", x.c_str()); if(stat = sstm("D:\\working\\" + x + ".exe < D:\\working\\data.in > D:\\working\\" + x + ".out")) { printf("%s.exe returned %d\n", x.c_str(), stat); return 64; } } for(int i=0;i+1<names.size();i++) { printf("[log] compare %s.out and %s.out\n", names[i].c_str(), names[i+1].c_str()); if(sstm("D:\\working\\diff.exe D:\\working\\" + names[i] + ".out D:\\working\\" + names[i+1] + ".out")) { printf("%s.out != %s.out.\n", names[i].c_str(), names[i+1].c_str()); goto ed; } } printf("Accepted.\n"); } while(true); ed: printf("Wrong Answer.\n"); return 0; }
|