Submission
Status:
PPPPPPPPPPPPPPPPPPPP
Subtask/Task Score:
100/100
Score: 100
User: Whatthepoop
Problemset: สุ่มสลับ
Language: c
Time: 0.001 second
Submitted On: 2025-10-12 23:38:45
#include <stdio.h>
#include <string.h>
long long fact(int n) {
long long f = 1;
for (int i = 2; i <= n; i++) f *= i;
return f;
}
int main() {
int pos; // ตัวนี้ไม่ได้ใช้จริง
scanf("%d", &pos);
char s[100];
scanf("%s", s);
int n = strlen(s);
// นับลำดับ
long long rank = 1; // เริ่มจาก 1
for (int i = 0; i < n; i++) {
int smaller = 0;
for (int j = i + 1; j < n; j++) {
if (s[j] < s[i]) smaller++;
}
rank += smaller * fact(n - i - 1);
}
printf("%lld\n", rank);
return 0;
}