QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#405005#3005. MonotonyLspeedRE 0ms0kbC++143.6kb2024-05-05 06:24:192024-05-05 06:24:19

Judging History

This is the latest submission verdict.

  • [2024-05-05 06:24:19]
  • Judged
  • Verdict: RE
  • Time: 0ms
  • Memory: 0kb
  • [2024-05-05 06:24:19]
  • Submitted

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));
vector<vector<ll>> dp(c + 5, vector<ll>((1<<20) + 10, 0LL));

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];

    
    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]);
        // sort(all(coord));
        // 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]);

        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[j][parity[i][j]] + 1;
                dp[i][parity[i][j]] += dp[j][parity[i][j]] + 1;
            }
        }

        FOR (i, 0, c) {
            for (int j = 0; j <= i-1; j++) {
                dp[i][parity[i][j]] = 0;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

詳細信息

Test #1:

score: 0
Runtime Error

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:


result: