QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#154238 | #5158. Interview Question | acm202226010311 | WA | 2ms | 3644kb | C++14 | 2.3kb | 2023-08-31 15:28:07 | 2023-08-31 15:28:08 |
Judging History
answer
#include<iostream>
#include<string>
#include<set>
using namespace std;
int a[100005],b[100005],c[100005],d[100005];
int a1[100005],b1[100005];
int cnt1,cnt2,cnt3,cnt4,cnt5;
set<int>set1,set2;
int main()
{
int C,D;
cin>>C>>D;
for(int i=C;i<=D;i++)
{
string s1;
string s2;
s2=to_string(i);
cin>>s1;
if(s1==s2)
{ d[cnt3++]=i;
}
else if(s1=="Fizz")
{ b[cnt1++]=i;
a1[cnt4++]=i;
}
else if(s1=="Buzz")
c[cnt2++]=i,b1[cnt5++]=i;
else
{
b[cnt1++]=i;
c[cnt2++]=i;
}
}
for(int i=0;i<cnt3;i++)
{
for(int j=1;j*j<=d[i];j++)
{
if(d[i]%j==0)
a[j]=-1,a[d[i]/j]=-1;
}
}
for(int i=0;i<cnt1;i++)
{
if(i==0)
{
for(int j=1;j*j<=b[i];j++)
{
if(b[i]%j==0)
{
if(a[j]!=-1)
set1.insert(j);
if(a[b[i]/j]!=-1)
set1.insert(b[i]/j);
}
}
}
else
{ int l[10000];
int z=0;
for(auto it:set1)
{
if(b[i]%it!=0)
{
l[z++]=it;
}
}
for(int k=0;k<z;k++)
set1.erase(l[k]);
}
}
for(int i=0;i<cnt5;i++)
{
int l[10000];
int z=0;
for(auto it:set1)
{
if(b1[i]%it==0)
{
l[z++]=it;
}
}
for(int k=0;k<z;k++)
set1.erase(l[k]);
}
for(int i=0;i<cnt2;i++)
{
if(i==0)
{
for(int j=1;j*j<=c[i];j++)
{
if(c[i]%j==0)
{
if(a[j]!=-1)
set2.insert(j);
if(a[c[i]/j]!=-1)
set2.insert(c[i]/j);
}
}
}
else
{ int l[10000];
int z=0;
for(auto it:set2)
{
if(c[i]%it!=0)
{
l[z++]=it;
}
}
for(int k=0;k<z;k++)
set2.erase(l[k]);
}
}
for(int i=0;i<cnt4;i++)
{
int l[10000];
int z=0;
for(auto it:set2)
{
if(a1[i]%it==0)
{
l[z++]=it;
}
}
for(int k=0;k<z;k++)
set2.erase(l[k]);
}
int ans1=0,ans2=0;
if(cnt1==0&&cnt2!=0)
{ans1=D+1;
ans2=*set2.begin() ;
}
else if(cnt2==0&&cnt1!=0)
{ans2=D+2;
ans1=*set1.begin() ;
}
else if(cnt1==0&&cnt2==0)
{
ans1=D+1;ans2=D+2;
}
else if(cnt1&&cnt2)
{
for(auto it:set1)
{ ans1=it;
bool flag=false;
for(auto it1:set2)
{
if(it1!=ans1 )
{ flag=true;
ans2=it1;
break;
}
}
if(flag)
break;
}
}
cout<<ans1<<" "<<ans2;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3564kb
input:
7 11 7 8 Fizz Buzz 11
output:
3 5
result:
ok
Test #2:
score: 0
Accepted
time: 2ms
memory: 3624kb
input:
49999 50002 49999 FizzBuzz 50001 Fizz
output:
2 4
result:
ok
Test #3:
score: 0
Accepted
time: 1ms
memory: 3556kb
input:
8 11 Buzz Buzz FizzBuzz Buzz
output:
5 1
result:
ok
Test #4:
score: 0
Accepted
time: 1ms
memory: 3620kb
input:
10 15 10 11 12 13 14 15
output:
16 17
result:
ok
Test #5:
score: 0
Accepted
time: 1ms
memory: 3612kb
input:
17 17 17
output:
18 19
result:
ok
Test #6:
score: 0
Accepted
time: 1ms
memory: 3636kb
input:
13 13 Fizz
output:
1 15
result:
ok
Test #7:
score: 0
Accepted
time: 1ms
memory: 3488kb
input:
20 20 Buzz
output:
21 1
result:
ok
Test #8:
score: 0
Accepted
time: 1ms
memory: 3640kb
input:
30 30 FizzBuzz
output:
1 2
result:
ok
Test #9:
score: 0
Accepted
time: 1ms
memory: 3524kb
input:
9 10 Buzz FizzBuzz
output:
2 1
result:
ok
Test #10:
score: -100
Wrong Answer
time: 0ms
memory: 3644kb
input:
2 6 2 3 4 5 FizzBuzz
output:
6 0
result:
wrong answer Integer parameter [name=b] equals to 0, violates the range [1, 1000000]