QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#640267 | #8781. Element-Wise Comparison | qianchen06 | WA | 0ms | 3788kb | C++14 | 1.2kb | 2024-10-14 10:16:12 | 2024-10-14 10:16:16 |
Judging History
answer
#include <iostream>
#include <vector>
#include <bitset>
using namespace std;
const int MAXN = 5000;
bitset<MAXN> B[MAXN];
int main()
{
int n, m;
cin >> n >> m;
vector<int> p(n);
// 输入排列 p
for (int i = 0; i < n; ++i)
{
cin >> p[i];
}
// 构建布尔矩阵,C[l,s] 表示 p[l] < p[l+s]
for (int l = 0; l < n; ++l)
{
for (int s = 1; l + s < n; ++s)
{
if (p[l] < p[l + s])
{
B[l][s] = 1;
}
}
}
// 计数符合条件的子数组对
int result = 0;
for (int i = 0; i <= n - m; ++i)
{
for (int j = i + m; j <= n - m; ++j)
{
// 比较区间 [i, i+m) 和 [j, j+m) 是否逐个小于
bool isValid = true;
for (int k = 0; k < m; ++k)
{
if (p[i + k] >= p[j + k])
{
isValid = false;
break;
}
}
if (isValid)
{
result++;
}
}
}
cout << result << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3788kb
input:
5 3 5 2 1 3 4
output:
0
result:
ok answer is '0'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3480kb
input:
5 2 3 1 4 2 5
output:
2
result:
ok answer is '2'
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3788kb
input:
4 2 1 2 3 4
output:
1
result:
wrong answer expected '3', found '1'