- 253's solution
-
P253's Solution
- @ 2026-4-21 18:22:07
直接对所有区间逐个判断即可,注意溢出问题。
#include <bits/stdc++.h>
using namespace std;
const int N = 100 + 12, V = 1e4 + 12;
int a[N], b[N][N];
int main()
{
freopen("multiply.in", "r", stdin);
freopen("multiply.out", "w", stdout);
int n, x;
cin >> n >> x;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
b[i][i] = a[i];
}
for (int i = 1; i <= n; i++)
for (int j = i + 1; j <= n; j++)
b[i][j] = min(b[i][j - 1] * a[j], V);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
if (b[i][j] == x)
{
cout << i << ' ' << j << endl;
return 0;
}
cout << -1 << endl;
return 0;
}