QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#101532 | #3005. Monotony | tom0727 | ML | 1983ms | 560496kb | C++14 | 6.3kb | 2023-04-30 06:22:27 | 2023-04-30 06:22:29 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#if __cplusplus >= 201103L
struct pairhash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
template<class T, class U>
size_t operator() (const pair<T,U> &p) const {
static const uint64_t FIXED_RANDOM = (uint64_t)chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(p.first + FIXED_RANDOM) ^ splitmix64(p.second+ FIXED_RANDOM);
}
};
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = (uint64_t)chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
inline int randint(int l, int r) {
return uniform_int_distribution<int>(l,r)(rng);
}
inline double randdouble(double l, double r) {
return uniform_real_distribution<double>(l,r)(rng);
}
#endif
#ifndef ONLINE_JUDGE
# define LOG(x) (cerr << #x << " = " << (x) << endl)
#else
# define LOG(x) 0
#endif
#define fastio ios::sync_with_stdio(false); cin.tie(0);
#define ll long long
#define ull unsigned long long
#define ll128 __int128_t
#define PI 3.14159265358979323846
#define abs(a) ((a>0)?a:-(a))
#define pii pair<int,int>
#define pll pair<ll,ll>
const long double pi = acos(-1.0);
const long double eps = (double)1e-8;
const int mod = 1e9+7;
template<class T>
T qpow(T a, int b) {
T res = 1;
while (b) {
if (b & 1) res *= a;
a *= a;
b >>= 1;
}
return res;
}
int norm(int x) {
if (x < 0) {
x += mod;
}
if (x >= mod) {
x -= mod;
}
return x;
}
struct Z {
int x;
Z(int x = 0) : x(norm(x)) {}
Z(ll x) : x(norm((int)(x % mod))) {}
int val() const {
return x;
}
Z operator-() const {
return Z(norm(mod - x));
}
Z inv() const {
assert(x != 0);
return qpow(*this, mod - 2);
}
Z &operator*=(const Z &rhs) {
x = (ll)(x) * rhs.x % mod;
return *this;
}
Z &operator+=(const Z &rhs) {
x = norm(x + rhs.x);
return *this;
}
Z &operator-=(const Z &rhs) {
x = norm(x - rhs.x);
return *this;
}
Z &operator/=(const Z &rhs) {
return *this *= rhs.inv();
}
friend Z operator*(const Z &lhs, const Z &rhs) {
Z res = lhs;
res *= rhs;
return res;
}
friend Z operator+(const Z &lhs, const Z &rhs) {
Z res = lhs;
res += rhs;
return res;
}
friend Z operator-(const Z &lhs, const Z &rhs) {
Z res = lhs;
res -= rhs;
return res;
}
friend Z operator/(const Z &lhs, const Z &rhs) {
Z res = lhs;
res /= rhs;
return res;
}
friend std::istream &operator>>(std::istream &is, Z &a) {
ll v;
is >> v;
a = Z(v);
return is;
}
friend std::ostream &operator<<(std::ostream &os, const Z &a) {
return os << a.val();
}
};
const int maxn = 1e5+5;
const int maxm = 2e5+55;
int n, m, a[21][21];
int ok[21][21];
bool good[21];
ll ans = 0;
int dp[21];
vector<pii> adj[(1<<20)+5];
inline void solve(int mask) {
memset(good, 1, sizeof(good));
memset(dp, 0, sizeof(dp));
vector<int> vec;
for (int i = 1; i <= n; i++) {
vec.clear();
for (int j = 1; j <= m; j++) {
if (mask&(1<<(j-1))) vec.push_back(a[i][j]);
}
// 看vec是否单调
if (vec.size() == 1) {
continue;
}
bool inc = (vec[1] > vec[0]);
for (int j = 1; j < vec.size(); j++) {
if (inc && vec[j] < vec[j-1]) good[i] = 0;
if (!inc && vec[j] > vec[j-1]) good[i] = 0;
}
}
vector<int> goods;
for (int i = 1; i <= n; i++) {
if (good[i]) goods.push_back(i);
}
vector<int> tmp;
ans += goods.size();
for (int ii = 0; ii < goods.size(); ii++) {
for (int jj = ii+1; jj < goods.size(); jj++) {
int i = goods[ii], j = goods[jj];
int nm = (mask & ok[i][j]);
// 1: < , 0 : >
adj[nm].push_back({i,j});
tmp.push_back(nm);
}
}
sort(tmp.begin(), tmp.end());
tmp.resize(unique(tmp.begin(), tmp.end()) - tmp.begin());
for (int nm : tmp) {
// int sum = 0;
for (pii p : adj[nm]) {
dp[p.second] += dp[p.first] + 1;
ans += dp[p.first] + 1;
// sum += dp[p.first] + 1;
}
for (pii p : adj[nm]) {
dp[p.first] = dp[p.second] = 0;
}
// printf("nm = %d, sum = %d, mask = %d\n",nm,sum,mask);
}
for (int nm : tmp) {
adj[nm].clear();
}
// if ((mask & ok[i][j]) == mask)
// for (int i = 1; i <= n; i++) {
// if (!good[i]) continue;
// dp[i] = 1;
// for (int j = i-1; j >= 1; j--) {
// if (!good[j]) continue;
// if ((mask & ok[j][i]) == mask) {
// dp[i] = max(dp[i], dp[j] + 1);
// // LOG(i);
// // LOG(dp[i]);
// // LOG(dp[i-1]);
// }
// }
// ans += (1<<(dp[i]-1));
// }
}
int main() {
fastio;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) cin >> a[i][j];
}
for (int i = 1; i <= n; i++) {
for (int j = i; j <= n; j++) {
for (int k = 1; k <= m; k++) {
if (a[i][k] <= a[j][k]) ok[i][j] |= (1<<(k-1));
}
}
}
for (int mask = 1; mask < (1<<m); mask++) {
solve(mask);
}
cout << ans << endl;
}
詳細信息
Test #1:
score: 100
Accepted
time: 144ms
memory: 28112kb
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:
40490
result:
ok answer is '40490'
Test #2:
score: 0
Accepted
time: 11ms
memory: 28064kb
input:
17 13 41 205 162 42 35 147 143 185 89 176 4 103 181 85 115 59 2 182 190 20 142 97 172 31 211 101 154 62 119 82 16 117 1 157 72 3 149 216 21 188 49 202 77 161 160 169 46 79 133 50 113 91 30 71 156 193 92 29 54 187 111 199 80 22 17 209 122 138 127 135 81 53 86 158 145 109 56 6 150 40 15 212 10 186 32 ...
output:
35799
result:
ok answer is '35799'
Test #3:
score: 0
Accepted
time: 4ms
memory: 27940kb
input:
1 1 1
output:
1
result:
ok answer is '1'
Test #4:
score: 0
Accepted
time: 4ms
memory: 28000kb
input:
1 2 1 2
output:
3
result:
ok answer is '3'
Test #5:
score: 0
Accepted
time: 2ms
memory: 28072kb
input:
1 2 2 1
output:
3
result:
ok answer is '3'
Test #6:
score: 0
Accepted
time: 222ms
memory: 27944kb
input:
1 20 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
output:
1048575
result:
ok answer is '1048575'
Test #7:
score: 0
Accepted
time: 3ms
memory: 27992kb
input:
2 1 1 2
output:
3
result:
ok answer is '3'
Test #8:
score: 0
Accepted
time: 4ms
memory: 28048kb
input:
2 1 2 1
output:
3
result:
ok answer is '3'
Test #9:
score: 0
Accepted
time: 7ms
memory: 28056kb
input:
2 2 1 2 3 4
output:
9
result:
ok answer is '9'
Test #10:
score: 0
Accepted
time: 3ms
memory: 28052kb
input:
2 2 1 3 4 2
output:
9
result:
ok answer is '9'
Test #11:
score: 0
Accepted
time: 1ms
memory: 28056kb
input:
2 2 2 1 4 3
output:
9
result:
ok answer is '9'
Test #12:
score: 0
Accepted
time: 5ms
memory: 28008kb
input:
2 2 3 2 4 1
output:
9
result:
ok answer is '9'
Test #13:
score: 0
Accepted
time: 7ms
memory: 28012kb
input:
2 2 4 3 2 1
output:
9
result:
ok answer is '9'
Test #14:
score: 0
Accepted
time: 3ms
memory: 28048kb
input:
4 4 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
output:
225
result:
ok answer is '225'
Test #15:
score: 0
Accepted
time: 4ms
memory: 27996kb
input:
4 4 1 2 3 4 8 7 6 5 9 10 11 12 16 15 14 13
output:
225
result:
ok answer is '225'
Test #16:
score: 0
Accepted
time: 2ms
memory: 28012kb
input:
4 4 4 5 1 3 11 6 13 10 16 2 9 8 14 15 12 7
output:
110
result:
ok answer is '110'
Test #17:
score: 0
Accepted
time: 0ms
memory: 28076kb
input:
20 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
output:
1048575
result:
ok answer is '1048575'
Test #18:
score: 0
Accepted
time: 410ms
memory: 29660kb
input:
20 19 180 179 178 177 176 175 174 173 172 190 189 188 187 186 185 184 183 182 181 161 160 159 158 157 156 155 154 153 171 170 169 168 167 166 165 164 163 162 142 141 140 139 138 137 136 135 134 152 151 150 149 148 147 146 145 144 143 123 122 121 120 119 118 117 116 115 133 132 131 130 129 128 127 12...
output:
3485104
result:
ok answer is '3485104'
Test #19:
score: 0
Accepted
time: 423ms
memory: 31156kb
input:
20 19 9 8 7 6 5 4 3 2 1 19 18 17 16 15 14 13 12 11 10 28 27 26 25 24 23 22 21 20 38 37 36 35 34 33 32 31 30 29 47 46 45 44 43 42 41 40 39 57 56 55 54 53 52 51 50 49 48 66 65 64 63 62 61 60 59 58 76 75 74 73 72 71 70 69 68 67 85 84 83 82 81 80 79 78 77 95 94 93 92 91 90 89 88 87 86 104 103 102 101 10...
output:
1702885800
result:
ok answer is '1702885800'
Test #20:
score: 0
Accepted
time: 1983ms
memory: 560496kb
input:
20 19 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 13...
output:
1125119902
result:
ok answer is '1125119902'
Test #21:
score: -100
Memory Limit Exceeded
input:
20 20 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 10...