QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#432836 | #6712. Sum of Factorials | surenjamts# | TL | 0ms | 3824kb | C++14 | 746b | 2024-06-07 18:32:52 | 2024-06-07 18:32:52 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
void solve() {
int n;
cin >> n;
if(n == -1) return;
long long fact[20];
fact[0] = 1;
for (int i = 1; i<=11; i++){
fact[i] = fact[i-1] * i;
}
map<int , bool > mp;
mp[0] = true;
mp[1] = true;
for(int i = 1; i<n; i++){
vector<int> temp;
for(auto it : mp) {
// cout << it.first << " " << fact[i] << endl;
if(it.first + fact[i] > n) continue;
temp.push_back(it.first + fact[i]);
}
for(auto it : temp) mp[it] = true;
}
// for(auto it : mp) cout << it.first << " ";
// cout << endl;
if(mp[n]) cout << "YES\n";
else cout << "NO\n";
solve();
}
signed main(){
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3824kb
input:
9 -1
output:
YES
result:
ok single line: 'YES'
Test #2:
score: -100
Time Limit Exceeded
input:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 715 716 717 718 719 720 721 722...
output:
YES YES YES YES YES NO YES YES YES YES YES NO NO NO NO NO NO NO NO NO NO YES YES YES YES YES NO YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES ...