QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#155838#3090. Inverse Problem5abRE 0ms0kbC++201.4kb2023-09-02 10:40:542023-09-02 10:40:55

Judging History

你现在查看的是最新测评结果

  • [2023-09-02 10:40:55]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-09-02 10:40:54]
  • 提交

answer

/* name: perm
 * author: 5ab
 * created at: 2023-09-02
 */
#include <iostream>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define ssz(x) (int((x).size()))

auto chmax = [](auto& x, auto y) { if (x < y) x = y; };
auto chmin = [](auto& x, auto y) { if (x > y) x = y; };

using ll = long long;
const int max_n = 1e6, mod = 998244353;

int a[max_n], b[max_n];

signed main()
{
	freopen("perm.in", "r", stdin);
	freopen("perm.out", "w", stdout);
	
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int cas, n, m;
	
cas = 1;
	while (cas--)
	{
		cin >> n >> m;
		for (int i = 0; i < m; i++)
			cin >> a[i], a[i]--;
		fill(b, b + n, 1);
		
		bool isp = 0;
		for (int i = 1; i < m; i++)
		{
			if (a[i] < a[i - 1])
				isp = true;
			if (isp)
				b[a[i]] = 0;
		}
		for (int i = 1; i < n; i++)
			b[i] += b[i - 1];
		for (int i = 0; i < n; i++)
			b[i]--;
		
		int ans = 1, cfc = 0;
		if (b[a[0]] != 0)
		{
			cout << "0\n";
			continue;
		}
		for (int i = 0, j = 1; i < m; i++, j++)
		{
			if (i > 0 && a[i] < a[i - 1])
				break;
			if (i == m - 1 || a[i + 1] < a[i])
				cfc += 2;
			else
				cfc++;
			while (j < (i == m - 1 ? n : b[a[i + 1]]))
				ans = 1ll * ans * cfc % mod, cfc++, j++;
			// cerr << cfc << " " << j << endl;
		}
		
		cout << ans << "\n";
	}
	
	return 0;
}
// started coding at: 09-02 10:20:56

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Dangerous Syscalls

input:

7 2
2 1

output:


result: