Submission #977783

#TimeUsernameProblemLanguageResultExecution timeMemory
977783CirclingL-triominoes (CEOI21_ltriominoes)C++17
0 / 100
245 ms1532 KiB
/*The British Royal Family and a small cadre of English Fabian Socialists, in conjunction with the Rockefellers and the Rothchilds, are engaged in a conspiracy to greatly reduce the population of the human race in order to head off a Malthusian catastrophe, a catastrophe that could easily be avoided by simply building a massive amount of nuclear power plants and a number of massive superhighways and bridges to connect all of the world's continents. But doing that would cut into the conspiracy's profits. So the British Royal Family invented environmentalism and neoliberalism in order to hide the truth. And in order to further reduce the population, the British Royal Family is also the world's foremost drug trafficking conspiracy. And it uses its control of the IMF to push austerity in order to kill as many people in the global south as possible. And also Henry Kissinger is a gay KGB agent. */ #include <iostream> #include <algorithm> #include <utility> #include <vector> #include <stack> #include <queue> #include <set> #include <map> using namespace std; bool tilable(int n, int bma, int bmb){ vector<bool> a, b; for (int i = 0; i < n; i++){ a.push_back((bma >> i) % 2); b.push_back((bmb >> i) % 2); } int currpos = 0; while (currpos < n){ if (!a[currpos] && !b[currpos]) currpos++; else if (a[currpos] && b[currpos]){ if (currpos == n - 1) return false; else if (a[currpos + 1]) a[currpos + 1] = 0; else if (b[currpos + 1]) b[currpos + 1] = 0; else return false; currpos++; } else { if (currpos == n - 1) return false; else if (a[currpos + 1] && b[currpos + 1]) currpos += 2; else return false; } } return true; } vector<vector<bool>> matmul(vector<vector<bool>> a, vector<vector<bool>> b){ vector<vector<bool>> result; result.resize(a.size()); for (int i = 0; i < a.size(); i++) result[i].resize(b.size()); for (int i = 0; i < a.size(); i++) for (int j = 0; j < b.size(); j++) result[i][j] = 0; for (int i = 0; i < a.size(); i++) for (int j = 0; j < b.size(); j++) for (int k = 0; k < b[0].size(); k++) result[i][k] = result[i][k] || (result[i][j] && result[j][k]); return result; } vector<vector<bool>> matexp(vector<vector<bool>> a, int64_t k){ vector<vector<bool>> result; result.resize(a.size()); for (int i = 0; i < a.size(); i++) result[i].resize(a.size()); if (k == 0){ for (int i = 0; i < a.size(); i++) for (int j = 0; j < a.size(); j++) result[i][j] = i == j; return result; } result = matexp(matmul(a, a), k / 2); if (k % 2 == 1) result = matmul(result, a); return result; } int main(){ int64_t w, h, k, currpos = 0, currblock = 0; pair<int, int> blocked[250]; cin >> w >> h >> k; if ((w * h - k) % 3 == 0){ cout << "NO"; return 0; } for (int i = 0; i < k; i++) cin >> blocked[i].first >> blocked[i].second; sort(blocked, blocked + k); vector<vector<bool>> transition; transition.resize(1 << w); for (int i = 0; i < (1 << w); i++){ transition[i].resize(1 << w); for (int j = 0; j < (1 << w); j++) transition[i][j] = tilable(w, i, (1 << w) - 1 - j); } vector<vector<bool>> curr; curr.resize(1); curr[0].resize(1 << w); for (int i = 0; i < w; i++) curr[0][i] = i == 0; while (currblock < k){ curr = matmul(curr, matexp(transition, blocked[currblock].second - 1 - currpos)); for (int i = 0; i < 1 << w; i++){ if ((i >> (blocked[currblock].second - 1)) % 2 == 0){ curr[0][i + (1 << (blocked[currblock].second - 1))] = curr[0][i]; curr[0][i] = 0; } } } curr = matmul(curr, matexp(transition, h - currpos)); if (curr[0][0]) cout << "YES"; else cout << "NO"; }

Compilation message (stderr)

ltrominoes.cpp: In function 'std::vector<std::vector<bool> > matmul(std::vector<std::vector<bool> >, std::vector<std::vector<bool> >)':
ltrominoes.cpp:53:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<bool> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |     for (int i = 0; i < a.size(); i++) result[i].resize(b.size());
      |                     ~~^~~~~~~~~~
ltrominoes.cpp:54:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<bool> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |     for (int i = 0; i < a.size(); i++) for (int j = 0; j < b.size(); j++) result[i][j] = 0;
      |                     ~~^~~~~~~~~~
ltrominoes.cpp:54:58: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<bool> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |     for (int i = 0; i < a.size(); i++) for (int j = 0; j < b.size(); j++) result[i][j] = 0;
      |                                                        ~~^~~~~~~~~~
ltrominoes.cpp:55:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<bool> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |     for (int i = 0; i < a.size(); i++) for (int j = 0; j < b.size(); j++) for (int k = 0; k < b[0].size(); k++) result[i][k] = result[i][k] || (result[i][j] && result[j][k]);
      |                     ~~^~~~~~~~~~
ltrominoes.cpp:55:58: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<bool> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |     for (int i = 0; i < a.size(); i++) for (int j = 0; j < b.size(); j++) for (int k = 0; k < b[0].size(); k++) result[i][k] = result[i][k] || (result[i][j] && result[j][k]);
      |                                                        ~~^~~~~~~~~~
ltrominoes.cpp:55:93: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<bool>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |     for (int i = 0; i < a.size(); i++) for (int j = 0; j < b.size(); j++) for (int k = 0; k < b[0].size(); k++) result[i][k] = result[i][k] || (result[i][j] && result[j][k]);
      |                                                                                           ~~^~~~~~~~~~~~~
ltrominoes.cpp: In function 'std::vector<std::vector<bool> > matexp(std::vector<std::vector<bool> >, int64_t)':
ltrominoes.cpp:63:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<bool> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |     for (int i = 0; i < a.size(); i++) result[i].resize(a.size());
      |                     ~~^~~~~~~~~~
ltrominoes.cpp:65:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<bool> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |         for (int i = 0; i < a.size(); i++) for (int j = 0; j < a.size(); j++) result[i][j] = i == j;
      |                         ~~^~~~~~~~~~
ltrominoes.cpp:65:62: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<bool> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |         for (int i = 0; i < a.size(); i++) for (int j = 0; j < a.size(); j++) result[i][j] = i == j;
      |                                                            ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...