QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#404989 | #3005. Monotony | Lspeed# | WA | 85ms | 3848kb | C++14 | 4.2kb | 2024-05-05 05:49:12 | 2024-05-05 05:49:13 |
Judging History
answer
#include <iostream> // Input/output stream objects
#include <fstream> // File stream objects
#include <sstream> // String stream objects
#include <iomanip> // Input/output manipulators
#include <string> // String class and functions
#include <vector> // Dynamic array
#include <list> // Doubly linked list
#include <set> // Set container
#include <map> // Map container
#include <queue> // Queue container
#include <stack> // Stack container
#include <algorithm> // Algorithms on sequences (e.g., sort, find)
#include <cmath> // Mathematical functions
#include <ctime> // Date and time functions
#include <cstdlib> // General purpose functions (e.g., memory management)
#include <cstring> // C-style string functions
#include <cctype> // Character classification functions
#include <cassert> // Assert function for debugging
#include <exception> // Standard exceptions
#include <functional> // Function objects
#include <iterator> // Iterator classes
#include <limits> // Numeric limits
#include <locale> // Localization and internationalization
#include <numeric> // Numeric operations (e.g., accumulate)
#include <random> // Random number generators
#include <stdexcept> // Standard exception classes
#include <typeinfo> // Runtime type information
#include <utility> // Utility components (e.g., std::pair)
#include <bitset>
using namespace std;
#define FOR(i, a, b) for(int i = a; i < (b); i++)
#define FORE(i, a, b) for(int i = a; i <= (b); i++)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define x first
#define y second
#define mp make_pair
#define PI 3.141592653
const double eps = 1e-9;
int r, c;
ll ans;
vector<vector<int>> grid(22, vector<int>(22, 0));
int get_id(int x, vector<int> &coord) { return lower_bound(all(coord), x) - coord.begin(); }
bool check_mono(int col, int rows) {
vector<int> num;
FOR (i, 0, r) if ((1 << i) & rows) num.push_back(grid[i][col]);
if (sz(num) == 1) return true;
bool inc = num[0] < num[1];
FOR (i, 1, sz(num) - 1) if (inc != num[i] < num[i+1]) return false;
return true;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> r >> c;
FOR (i, 0, r) FOR (j, 0, c) cin >> grid[i][j];
vector<vector<ll>> dp(c + 5, vector<ll>(405, 0LL));
FOR (rows, 1, 1 << r) {
// preprocess
// parity[i][j] from j to i (1 = increase, 0 = decrease)
vector<vector<int>> parity(22, vector<int>(22, 0));
vector<int> coord;
FOR (i, 0, c) FOR (j, i+1, c) {
FOR (k, 0, r) if ((rows & (1 << k)) != 0 && grid[k][j] > grid[k][i]) parity[j][i] += (1 << k);
}
FOR (i, 1, c) FORE (j, 0, i-1) coord.push_back(parity[i][j]);
// cout << "ROWS: " << rows << endl;
// sort(all(coord));
// FOR (i, 0, c) {
// FOR (j, 0, c) {
// cout << parity[i][j] << " ";
// }
// cout << endl;
// }
// cout << "AFTER " << endl;
coord.resize(unique(all(coord)) - coord.begin());
auto get_id = [&](int x) { return lower_bound(all(coord), x) - coord.begin(); };
FOR (i, 1, c) FORE (j, 0, i-1) parity[i][j] = get_id(parity[i][j]);
// FOR (i, 0, c) {
// FOR (j, 0, c) {
// cout << parity[i][j] << " ";
// }
// cout << endl;
// }
// cout << endl;
// dpdpdpdpdp
// cout << "DUBBMY : " << dp[0][0] << endl;
vector<bool> is_mono(c + 5, true);
FOR (i, 0, c) is_mono[i] = check_mono(i, rows);
FOR (i, 0, c) {
if (!is_mono[i]) continue;
ans += 1;
for (int j = 0; j <= i-1; j++) if (is_mono[j]) {
ans += (dp[i][parity[i][j]] = dp[j][parity[i][j]] + 1);
// cout << "CUR I J ans " << i << " " << j << " " << ans << endl;
}
}
// FOR (i, 0, c) {
// for (int j = 0; j < sz(coord); j++) cout << dp[i][j] << " ";
// cout << endl;
// }
// cout << "CURANS: " << ans << endl;
}
cout << ans << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 85ms
memory: 3848kb
input:
13 17 155 221 29 114 165 175 120 107 27 134 125 116 11 56 100 20 15 88 128 38 111 198 212 173 136 44 164 64 150 83 19 93 197 194 219 25 16 50 2 55 151 34 163 76 217 209 141 174 80 144 159 60 156 54 149 97 28 102 145 26 35 188 160 65 152 135 6 21 8 62 195 70 127 30 171 205 147 177 210 117 10 103 161 ...
output:
52106
result:
wrong answer expected '40490', found '52106'