#14850: 為甚麼TLE


william100263@gmail.com (蓋了)

School : 臺北市私立延平高級中學
ID : 69101
IP address : [203.72.178.252]
Last Login :
2019-05-08 17:48:05
c640. 滿滿的糖果屋 #1 -- it's david | From: [203.72.178.252] | Post Date : 2018-08-09 14:29

#include <iostream>
#include <cstring>
using namespace std;
int main()
{
ios::sync_with_stdio(0);
int a,b;
string s;
while(1)
{
cin>>a>>b;
cin.ignore();
getline(cin,s);
int temp=0,array[5],m=0,min=20000000;
for(int i=0;i<s.size();i++)
{
if(s[i]>='0'&&s[i]<='9') {temp*=10; temp+=(s[i]-48);}
if(s[i]==' '&&s[i-1]>='0'&&s[i-1]<='9') {array[m]=temp; if(temp<min) min=temp; temp=0; m++;}
if(i==s.size()-1) {array[m]=temp; if(temp<min) min=temp; m++;}
}
int ans;
for(int i=1;i<=min;i++)
{
int flag=0;
for(int j=m-1;j>=1;j--)
{
if(array[j]%i!=0) {flag=1; break;}
}
if(flag==0) {ans=i; break;}
}
int firstanswer=ans;
for(int i=0;i<m;i++)
{
firstanswer*=(array[i]/ans);
}
int k=firstanswer;
for(int i=firstanswer;i<=a;i+=k)
{
cout<<i+b<<endl;
}
}

}

 
ZeroJudge Forum