QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#432860#6712. Sum of Factorialssurenjamts#AC ✓32ms3728kbC++14729b2024-06-07 19:12:152024-06-07 19:12:16

Judging History

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

  • [2024-06-07 19:12:16]
  • 评测
  • 测评结果:AC
  • 用时:32ms
  • 内存:3728kb
  • [2024-06-07 19:12:15]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std; 
#define int long long 
const int N = 1e6 + 5;
bool ans[N+5];
signed main(){
	int fact[20];
	fact[0] = 1;
	for (int i = 1; i<=11; i++){
	   fact[i] = fact[i-1] * i;	
		
	}   
//	cout << fact[11];                 

	ans[0] = true;
	ans[1] = true;
	for(int k = 1; k<=11; k++){
		  for(int i = N; i>=0; i--){
		  	   if(ans[i]) {
		  	   	     if(i + fact[k] > N) continue;
		  	   	    ans[i + fact[k]] = true;
		  	   }
		  }
	
	}

	int A = 0;
	while(true) {
		  cin >> A;
		  if(A == 0) {
		  	    cout << "NO\n";
		  	    continue;
	
		  }
		  if( A < 0) break;
		  if(ans[A]) cout << "YES\n";
		  else cout << "NO\n";
		
	}
	
	
	
 
	
	
}

详细

Test #1:

score: 100
Accepted
time: 7ms
memory: 3632kb

input:

9
-1

output:

YES

result:

ok single line: 'YES'

Test #2:

score: 0
Accepted
time: 32ms
memory: 3728kb

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:

NO
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
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
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
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
YES
Y...

result:

ok 29987 lines