Submission #714127

# Submission time Handle Problem Language Result Execution time Memory
714127 2023-03-24T02:10:20 Z mongla Preokret (COCI18_preokret) C++17
50 / 50
1 ms 340 KB
#include<bits/stdc++.h>
using namespace std;
long long n,m,ans=0,anss=0,ld;
int a[3000],b[3000],jsa[3000],jsb[3000];
int main(){
	cin>>n;
	for(int i=1; i<=n; i++){
		cin>>a[i];
		if(a[i]<=1440) ans++;
		jsa[a[i]]=1;
	}
	scanf("%lld",&m);
	for(int i=1; i<=m; i++){
		cin>>b[i];
		if(b[i]<=1440) ans++;
		jsb[b[i]]=1;
	}
	cout<<ans<<endl;

	for(int i=1; i<=3000; i++)
		jsa[i]+=jsa[i-1],jsb[i]+=jsb[i-1];

	for(int i=1; i<=3000; i++)
	{
		if(jsa[i]>jsb[i] && jsa[i-1]==jsb[i-1] && ld==2)
			anss++;
		if(jsa[i]<jsb[i] && jsa[i-1]==jsb[i-1] && ld==1)
			anss++;
		if(jsa[i]!=jsb[i])
		{
			if(jsa[i]>jsb[i]) ld=1;
			else ld=2;
		}
	}
	cout<<anss;
	return 0;
}

Compilation message

preokret.cpp: In function 'int main()':
preokret.cpp:12:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |  scanf("%lld",&m);
      |  ~~~~~^~~~~~~~~~~
preokret.cpp:21:9: warning: iteration 2999 invokes undefined behavior [-Waggressive-loop-optimizations]
   21 |   jsa[i]+=jsa[i-1],jsb[i]+=jsb[i-1];
      |   ~~~~~~^~~~~~~~~~
preokret.cpp:20:16: note: within this loop
   20 |  for(int i=1; i<=3000; i++)
      |               ~^~~~~~
preokret.cpp:25:11: warning: iteration 2999 invokes undefined behavior [-Waggressive-loop-optimizations]
   25 |   if(jsa[i]>jsb[i] && jsa[i-1]==jsb[i-1] && ld==2)
      |      ~~~~~^
preokret.cpp:23:16: note: within this loop
   23 |  for(int i=1; i<=3000; i++)
      |               ~^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct