Submission #1870869
Source Code Expand
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<ctime>
#include<utility>
#include<cmath>
#include<functional>
#include<queue>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
void sort(int &a,int &b)
{
if(a>b)
swap(a,b);
}
void open(const char *s)
{
#ifndef ONLINE_JUDGE
char str[100];
sprintf(str,"%s.in",s);
freopen(str,"r",stdin);
sprintf(str,"%s.out",s);
freopen(str,"w",stdout);
#endif
}
int rd()
{
int s=0,c;
while((c=getchar())<'0'||c>'9');
do
{
s=s*10+c-'0';
}
while((c=getchar())>='0'&&c<='9');
return s;
}
int upmin(int &a,int b)
{
if(b<a)
{
a=b;
return 1;
}
return 0;
}
int upmax(int &a,int b)
{
if(b>a)
{
a=b;
return 1;
}
return 0;
}
int gcd(int a,int b)
{
return b?gcd(b,a%b):a;
}
priority_queue<int> q;
int d[2010];
vector<int> g[2010],g2[2010];
int a[2010];
int b[2010];
pii c[2010];
void dfs(int x)
{
b[x]=1;
for(auto v:g[x])
if(!b[v])
{
dfs(v);
g2[x].push_back(v);
d[v]++;
}
}
int main()
{
int n;
scanf("%d",&n);
int i,j;
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
c[i].first=a[i];
c[i].second=i;
}
sort(c+1,c+n+1);
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
if(gcd(a[c[i].second],a[c[j].second])!=1)
g[c[i].second].push_back(c[j].second);
for(i=1;i<=n;i++)
if(!b[c[i].second])
dfs(c[i].second);
for(i=1;i<=n;i++)
if(!d[i])
q.push(i);
for(i=1;i<=n;i++)
{
int x=q.top();
q.pop();
printf("%d ",a[x]);
for(auto v:g2[x])
{
d[v]--;
if(!d[v])
q.push(v);
}
}
return 0;
}
Submission Info
Submission Time |
|
Task |
E - Rearranging |
User |
yww |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
1707 Byte |
Status |
WA |
Exec Time |
505 ms |
Memory |
16000 KB |
Compile Error
./Main.cpp: In function ‘void open(const char*)’:
./Main.cpp:25:24: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’, declared with attribute warn_unused_result [-Wunused-result]
freopen(str,"r",stdin);
^
./Main.cpp:27:25: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’, declared with attribute warn_unused_result [-Wunused-result]
freopen(str,"w",stdout);
^
./Main.cpp: In function ‘int main()’:
./Main.cpp:83:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
^
./Main.cpp:87:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&a[i]);
^
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
0 / 1600 |
Status |
|
|
Set Name |
Test Cases |
Sample |
sample1.txt, sample2.txt |
All |
sample1.txt, sample2.txt, in1.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, in17.txt, in18.txt, in19.txt, in2.txt, in20.txt, in21.txt, in22.txt, in23.txt, in24.txt, in25.txt, in26.txt, in27.txt, in28.txt, in29.txt, in3.txt, in30.txt, in31.txt, in32.txt, in33.txt, in34.txt, in35.txt, in36.txt, in37.txt, in38.txt, in39.txt, in4.txt, in40.txt, in41.txt, in42.txt, in43.txt, in44.txt, in45.txt, in5.txt, in6.txt, in7.txt, in8.txt, in9.txt, sample1.txt, sample2.txt |
Case Name |
Status |
Exec Time |
Memory |
in1.txt |
WA |
501 ms |
9344 KB |
in10.txt |
WA |
505 ms |
9856 KB |
in11.txt |
WA |
427 ms |
1536 KB |
in12.txt |
WA |
430 ms |
1536 KB |
in13.txt |
WA |
427 ms |
1536 KB |
in14.txt |
WA |
429 ms |
1536 KB |
in15.txt |
WA |
428 ms |
1536 KB |
in16.txt |
AC |
436 ms |
15872 KB |
in17.txt |
AC |
434 ms |
16000 KB |
in18.txt |
WA |
433 ms |
15872 KB |
in19.txt |
AC |
434 ms |
15872 KB |
in2.txt |
WA |
502 ms |
9344 KB |
in20.txt |
AC |
433 ms |
15872 KB |
in21.txt |
WA |
325 ms |
512 KB |
in22.txt |
WA |
325 ms |
512 KB |
in23.txt |
WA |
326 ms |
512 KB |
in24.txt |
WA |
324 ms |
512 KB |
in25.txt |
WA |
324 ms |
512 KB |
in26.txt |
WA |
428 ms |
1536 KB |
in27.txt |
WA |
429 ms |
1536 KB |
in28.txt |
WA |
426 ms |
1536 KB |
in29.txt |
WA |
430 ms |
1536 KB |
in3.txt |
WA |
502 ms |
9088 KB |
in30.txt |
WA |
429 ms |
1664 KB |
in31.txt |
AC |
1 ms |
384 KB |
in32.txt |
AC |
1 ms |
384 KB |
in33.txt |
AC |
1 ms |
384 KB |
in34.txt |
WA |
381 ms |
512 KB |
in35.txt |
WA |
380 ms |
512 KB |
in36.txt |
WA |
450 ms |
2944 KB |
in37.txt |
WA |
449 ms |
2944 KB |
in38.txt |
WA |
451 ms |
2944 KB |
in39.txt |
WA |
454 ms |
3072 KB |
in4.txt |
WA |
503 ms |
9216 KB |
in40.txt |
WA |
449 ms |
2816 KB |
in41.txt |
WA |
450 ms |
2944 KB |
in42.txt |
WA |
452 ms |
2944 KB |
in43.txt |
WA |
449 ms |
2944 KB |
in44.txt |
WA |
450 ms |
2816 KB |
in45.txt |
WA |
452 ms |
2944 KB |
in5.txt |
WA |
501 ms |
9088 KB |
in6.txt |
WA |
502 ms |
9600 KB |
in7.txt |
WA |
502 ms |
9856 KB |
in8.txt |
WA |
505 ms |
9472 KB |
in9.txt |
WA |
502 ms |
9216 KB |
sample1.txt |
AC |
1 ms |
384 KB |
sample2.txt |
AC |
1 ms |
384 KB |