Submission
Status:
PPPPPPPPPPPPPPPPPPPP
Subtask/Task Score:
100/100
Score: 100
User: ssens3
Problemset: สุ่มสลับ
Language: cpp
Time: 0.004 second
Submitted On: 2026-10-05 07:59:19
#include <iostream>
#include <string>
using namespace std;
int fac(int n, int s = 1) {
for (int i = 2; i <= n; i++) s *= i;
return s;
}
int main() {
int n, r, c, s = 0; cin >> n; r = n;
string str, ref = ""; cin >> str;
for (int i = 0; i < n; i++) {
c = 0;
for (int j = i; j < n; j++)
if (str[j] < str[i]) c++;
s += c * fac(r - 1); r--;
}
cout << s + 1;
}