제출 #565369

#제출 시각아이디문제언어결과실행 시간메모리
565369shrimbSaveit (IOI10_saveit)C++17
100 / 100
348 ms14024 KiB
#include "grader.h" #include "encoder.h" #include"bits/stdc++.h" using namespace std; #define BSZ 1665 bitset<BSZ> operator + (const bitset<BSZ> &a, const bitset<BSZ> &b) { if (b.count() == 0) return a; return (a^b) + ((a&b)<<1); } vector<int> b2t(const vector<bool>& in);// { // vector<int> out; // for (bool carry : in) { // for (int& trit : out) { // int new_trit = 2 * trit + carry; // carry = new_trit / 3; // trit = new_trit % 3; // } // if (carry) { // out.push_back(1); // } // } // out.reserve(out.size()); // return out; // } void encode(int n, int h, int p, int *v1, int *v2){ vector<int> adj[n]; for (int i = 0 ; i < p ; i++) { adj[v1[i]].push_back(v2[i]); adj[v2[i]].push_back(v1[i]); } int par[n]; { queue<int> q; vector<bool> vis(n); q.push(0); while (q.size()) { auto cur = q.front(); q.pop(); for (int j : adj[cur]) { if (!vis[j]) { vis[j] = 1; par[j] = cur; q.push(j); } } } } auto sendnum = [&](int x) { for (int k = 0 ; k < 10 ; k++) { encode_bit(!!(x & (1 << k))); } }; for (int i = 1 ; i < n ; i++) sendnum(par[i]); for (int i = 1 ; i < h ; i++) { queue<int> q; vector<int> dis(n, -1); dis[i] = 0; q.push(i); while (q.size()) { auto cur = q.front(); q.pop(); for (int j : adj[cur]) { if (dis[j] == -1) { dis[j] = dis[cur] + 1; q.push(j); } } } bitset<BSZ> b = 0; for (int i = 1 ; i < n ; i++) { int x = dis[i] - dis[par[i]]; // cerr << x << " "; b = b + b + b; if (x == 1) b = b + bitset<BSZ>(1); else if (x == -1) b = b + bitset<BSZ>(2); } // vector<bool> bin(BSZ); // int id = 0; for (int i = BSZ - 1 ; i >=0 ; i--) { encode_bit(b[i]); // bin[id++] = b[i]; } // auto t = b2t(bin); // cerr << "T(encode): "; // for (int j : t) cerr << j << " " ; // cerr << endl; } }
#include "grader.h" #include "decoder.h" #include "bits/stdc++.h" using namespace std; vector<int> b2t(const vector<bool>& in) { vector<int> out; for (bool carry : in) { for (int& trit : out) { int new_trit = 2 * trit + carry; carry = new_trit / 3; trit = new_trit % 3; } if (carry) { out.push_back(1); } } out.reserve(out.size()); return out; } void decode(int n, int h) { vector<int> adj[n]; int par[n]; auto getnum = [&]() { int ret = 0; for (int k = 0 ; k < 10 ; k++) { ret |= (1 << k)*decode_bit(); } return ret; }; for (int i = 1 ; i < n ; i++) { int x = getnum(); par[i] = x; adj[i].push_back(x); adj[x].push_back(i); } { queue<int> q; vector<int> dis(n, -1); dis[0] = 0; q.push(0); while (q.size()) { auto cur = q.front(); q.pop(); for (int j : adj[cur]) { if (dis[j] == -1) { dis[j] = dis[cur] + 1; q.push(j); } } } for (int i = 0 ; i < n ; i++) { hops(0, i, dis[i]); } } int w[n][n]; for (int i = 1 ; i < h ; i++) { vector<bool> b; for (int j = 0 ; j < 1665 ; j++) b.push_back(decode_bit()); vector<int> t = b2t(b); while (t.size() < n - 1) t.push_back(0); reverse(t.begin(), t.end()); // cerr << "t(" << t.size() << "): "; // for (auto k : t) cerr << k << " "; // cerr << endl; for (int j = 1 ; j < n ; j++) { int v = t[j-1]; if (v == 2) v = -1; w[par[j]][j] = v; w[j][par[j]] = -v; } queue<int> q; vector<int> dis(n, -1e9); dis[i] = 0; q.push(i); while (q.size()) { auto cur = q.front(); q.pop(); for (int j : adj[cur]) { if (dis[j] == -1e9) { dis[j] = dis[cur] + w[cur][j]; q.push(j); } } } for (int j = 0 ; j < n ; j++) { hops(i, j, dis[j]); } } }

컴파일 시 표준 에러 (stderr) 메시지

decoder.cpp: In function 'void decode(int, int)':
decoder.cpp:60:25: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   60 |         while (t.size() < n - 1) t.push_back(0);
      |                ~~~~~~~~~^~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...