QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#57777 | #2510. Make Numbers | As3b_team_f_masr# | AC ✓ | 2ms | 3740kb | C++ | 2.8kb | 2022-10-22 21:27:37 | 2022-10-22 21:27:40 |
Judging History
answer
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define sc second
int cnt=0,tot;
vector<int> v;
set<int> s;
int main()
{
int a[4];
for(int i=0;i<4;i++)cin>>a[i];
sort(a,a+4);
do{
for(int i=0;i<(1<<3);i++)
{
v.clear();
v.push_back(a[0]);
for(int j=0;j<3;j++)
{
if(i&(1<<j))
{
int x=v.back();
v.pop_back();
x*=10;
x+=a[j+1];
v.push_back(x);
}
else
{
v.push_back(a[j+1]);
}
}
if(v.size()==1)continue;
if(v.size()==2)
{
s.insert(v[0]*v[1]) ;
s.insert(v[0]-v[1]) ;
s.insert(v[0]+v[1]) ;
}
else if(v.size()==3)
{
s.insert(v[0]*v[1]*v[2]) ;
s.insert(v[0]*v[1]-v[2]) ;
s.insert(v[0]*v[1]+v[2]) ;
s.insert(v[0]-v[1]-v[2]) ;
s.insert(v[0]-v[1]*v[2]) ;
s.insert(v[0]-v[1]+v[2]) ;
s.insert(v[0]+v[1]+v[2]) ;
s.insert(v[0]+v[1]-v[2]) ;
s.insert(v[0]+v[1]*v[2]) ;
}
else if(v.size()==4)
{
s.insert(v[0]*v[1]*v[2]*v[3]) ;
s.insert(v[0]*v[1]-v[2]*v[3]) ;
s.insert(v[0]*v[1]+v[2]*v[3]) ;
s.insert(v[0]-v[1]-v[2]*v[3]) ;
s.insert(v[0]-v[1]*v[2]*v[3]) ;
s.insert(v[0]-v[1]+v[2]*v[3]) ;
s.insert(v[0]+v[1]+v[2]*v[3]) ;
s.insert(v[0]+v[1]-v[2]*v[3]) ;
s.insert(v[0]+v[1]*v[2]*v[3]) ;
//
s.insert(v[0]*v[1]*v[2]+v[3]) ;
s.insert(v[0]*v[1]-v[2]+v[3]) ;
s.insert(v[0]*v[1]+v[2]+v[3]) ;
s.insert(v[0]-v[1]-v[2]+v[3]) ;
s.insert(v[0]-v[1]*v[2]+v[3]) ;
s.insert(v[0]-v[1]+v[2]+v[3]) ;
s.insert(v[0]+v[1]+v[2]+v[3]) ;
s.insert(v[0]+v[1]-v[2]+v[3]) ;
s.insert(v[0]+v[1]*v[2]+v[3]) ;
//
s.insert(v[0]*v[1]*v[2]-v[3]) ;
s.insert(v[0]*v[1]-v[2]-v[3]) ;
s.insert(v[0]*v[1]+v[2]-v[3]) ;
s.insert(v[0]-v[1]-v[2]-v[3]) ;
s.insert(v[0]-v[1]*v[2]-v[3]) ;
s.insert(v[0]-v[1]+v[2]-v[3]) ;
s.insert(v[0]+v[1]+v[2]-v[3]) ;
s.insert(v[0]+v[1]-v[2]-v[3]) ;
s.insert(v[0]+v[1]*v[2]-v[3]) ;
}
}
}while(next_permutation(a,a+4));
for(auto x:s)
{
if(x>=0)
{
cnt++;
}
}
cout<<cnt;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3732kb
input:
1 1 1 1
output:
15
result:
ok single line: '15'
Test #2:
score: 0
Accepted
time: 2ms
memory: 3596kb
input:
1 1 1 1
output:
15
result:
ok single line: '15'
Test #3:
score: 0
Accepted
time: 2ms
memory: 3584kb
input:
1 1 2 1
output:
32
result:
ok single line: '32'
Test #4:
score: 0
Accepted
time: 2ms
memory: 3532kb
input:
1 2 4 8
output:
178
result:
ok single line: '178'
Test #5:
score: 0
Accepted
time: 2ms
memory: 3740kb
input:
1 3 3 8
output:
107
result:
ok single line: '107'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3664kb
input:
1 1 2 1
output:
32
result:
ok single line: '32'
Test #7:
score: 0
Accepted
time: 1ms
memory: 3568kb
input:
2 2 4 4
output:
58
result:
ok single line: '58'
Test #8:
score: 0
Accepted
time: 1ms
memory: 3464kb
input:
2 3 4 5
output:
183
result:
ok single line: '183'
Test #9:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
2 3 5 7
output:
191
result:
ok single line: '191'
Test #10:
score: 0
Accepted
time: 2ms
memory: 3656kb
input:
2 4 6 8
output:
172
result:
ok single line: '172'
Test #11:
score: 0
Accepted
time: 2ms
memory: 3588kb
input:
2 5 5 5
output:
54
result:
ok single line: '54'
Test #12:
score: 0
Accepted
time: 2ms
memory: 3596kb
input:
2 8 6 4
output:
172
result:
ok single line: '172'
Test #13:
score: 0
Accepted
time: 0ms
memory: 3684kb
input:
3 3 3 3
output:
22
result:
ok single line: '22'
Test #14:
score: 0
Accepted
time: 2ms
memory: 3584kb
input:
5 3 2 7
output:
191
result:
ok single line: '191'
Test #15:
score: 0
Accepted
time: 2ms
memory: 3608kb
input:
5 7 8 9
output:
217
result:
ok single line: '217'
Test #16:
score: 0
Accepted
time: 0ms
memory: 3692kb
input:
9 9 9 9
output:
20
result:
ok single line: '20'