Submission #109458

#TimeUsernameProblemLanguageResultExecution timeMemory
109458nikolapesic2802Mechanical Doll (IOI18_doll)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/rope> #define ll long long #define pb push_back #define sz(x) (int)(x).size() #define mp make_pair #define f first #define s second #define all(x) x.begin(), x.end() #define D(x) cerr << #x << " is " << (x) << "\n"; using namespace std; using namespace __gnu_pbds; using namespace __gnu_cxx; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key() template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; } template<class T> ostream& operator<<(ostream& os, const vector<T>& a){os << '{';for(int i=0;i<sz(a);i++){if(i>0&&i<sz(a))os << ", ";os << a[i];}os<<'}';return os;} template<class T> ostream& operator<<(ostream& os, const set<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;} template<class T> ostream& operator<<(ostream& os, const multiset<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;} template<class T1,class T2> ostream& operator<<(ostream& os, const map<T1,T2>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;} void answer(std::vector<int> C, std::vector<int> X, std::vector<int> Y); void create_circuit(int M, vector<int> A) { vector<int> sol(M+1),a; sol[0]=A[0]; for(int i=1;i<A.size();i++) sol[A[i-1]]=A[i]; answer(sol,a,a); } constexpr int P_MAX = 20000000; constexpr int S_MAX = 400000; int M, N; std::vector<int> A; bool answered; int S; std::vector<int> IC, IX, IY; int read_int() { int x; if (scanf("%d", &x) != 1) { fprintf(stderr, "Error while reading input\n"); exit(1); } return x; } void wrong_answer(const char *MSG) { printf("Wrong Answer: %s\n", MSG); exit(0); } void simulate() { if (S > S_MAX) { char str[50]; sprintf(str, "over %d switches", S_MAX); wrong_answer(str); } for (int i = 0; i <= M; ++i) { if (!(-S <= IC[i] && IC[i] <= M)) { wrong_answer("wrong serial number"); } } for (int j = 1; j <= S; ++j) { if (!(-S <= IX[j - 1] && IX[j - 1] <= M)) { wrong_answer("wrong serial number"); } if (!(-S <= IY[j - 1] && IY[j - 1] <= M)) { wrong_answer("wrong serial number"); } } int P = 0; std::vector<bool> state(S + 1, false); int pos = IC[0]; int k = 0; FILE *file_log = fopen("log.txt", "w"); fprintf(file_log, "0\n"); for (;;) { fprintf(file_log, "%d\n", pos); if (pos < 0) { if (++P > P_MAX) { fclose(file_log); char str[50]; sprintf(str, "over %d inversions", P_MAX); wrong_answer(str); } state[-pos] = !state[-pos]; pos = state[-pos] ? IX[-(1 + pos)] : IY[-(1 + pos)]; } else { if (pos == 0) { break; } if (k >= N) { fclose(file_log); wrong_answer("wrong motion"); } if (pos != A[k++]) { fclose(file_log); wrong_answer("wrong motion"); } pos = IC[pos]; } } fclose(file_log); if (k != N) { wrong_answer("wrong motion"); } for (int j = 1; j <= S; ++j) { if (state[j]) { wrong_answer("state 'Y'"); } } printf("Accepted: %d %d\n", S, P); } // namespace void answer(std::vector<int> C, std::vector<int> X, std::vector<int> Y) { if (answered) { wrong_answer("answered not exactly once"); } answered = true; // check if input format is correct if ((int)C.size() != M + 1) { wrong_answer("wrong array length"); } if (X.size() != Y.size()) { wrong_answer("wrong array length"); } S = X.size(); IC = C; IX = X; IY = Y; } int main() { M = read_int(); N = read_int(); A.resize(N); for (int k = 0; k < N; ++k) { A[k] = read_int(); } answered = false; create_circuit(M, A); if (!answered) { wrong_answer("answered not exactly once"); } FILE *file_out = fopen("out.txt", "w"); fprintf(file_out, "%d\n", S); for (int i = 0; i <= M; ++i) { fprintf(file_out, "%d\n", IC[i]); } for (int j = 1; j <= S; ++j) { fprintf(file_out, "%d %d\n", IX[j - 1], IY[j - 1]); } fclose(file_out); simulate(); return 0; }

Compilation message (stderr)

doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:32:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |     for(int i=1;i<A.size();i++)
      |                 ~^~~~~~~~~
/usr/bin/ld: /tmp/ccpMG5Gk.o: in function `answer(std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)':
grader.cpp:(.text+0x1f0): multiple definition of `answer(std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)'; /tmp/ccNijf8k.o:doll.cpp:(.text+0x1f0): first defined here
/usr/bin/ld: /tmp/ccpMG5Gk.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccNijf8k.o:doll.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status