11572 - Unique Snowflakes

All about problems in Volume 115. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: 11572 - Unique Snowflakes

Post by uDebug »

Here's some input / output that I found useful during testing / debugging.

Input:

Code: Select all

12
5
1
2
3
2
1
1
0
12
7
4
0
9
4
8
8
2
4
5
5
1
2
1
1
5
134
134
135
136
136
7
132
132
123
132
123
144
566
0
1
333
7
22
22
22
23
22
23
23
5
132
132
132
132
132
6
1 
2 
3 
2 
4 
5
11
1 
2
3 
5 
11 
12 
444 
2 
6 
7 
15
AC Output:

Code: Select all

3
1
4
1
3
4
0
1
2
1
4
9
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.
mhsn06
New poster
Posts: 16
Joined: Tue Apr 01, 2014 7:36 pm

Re: 11572 - Unique Snowflakes

Post by mhsn06 »

Thanks all. I got AC. But all the test cases help me greatly.
waled_salah
New poster
Posts: 7
Joined: Fri Dec 06, 2013 3:38 pm

Re: 11572 - Unique Snowflakes

Post by waled_salah »

Got WA, why ??

Code: Select all



import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {

		Scanner sc = new Scanner(System.in);
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int t = Integer.parseInt(br.readLine()); 
		while(t-->0)
		{
			int n =Integer.parseInt(br.readLine()); 
			Map<Integer,Integer>s = new TreeMap<Integer,Integer>();
			int max = Integer.MIN_VALUE;
			int count =0;
			while(n-->0)
			{
				int num = Integer.parseInt(br.readLine());
				if(!s.containsKey(num))
				{
					s.put(num, 1);
					count++;
					
				}
				else{
					max = Math.max(max, count);
					count =1;
					s = new TreeMap<Integer,Integer>();
				}
				
			}
			max = Math.max(max, count);
			
			System.out.println(max);
		}
	}

}


brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11572 - Unique Snowflakes

Post by brianfry713 »

Input:

Code: Select all

1
4
1
2
1
3
Output should be 3
Check input and AC output for thousands of problems on uDebug!
prajwal007
New poster
Posts: 1
Joined: Fri Mar 13, 2015 11:40 am

Re: 11572 - Unique Snowflakes

Post by prajwal007 »

getting runtime error in java but code works perfectly fine on inputs........any ideas?
incruator
New poster
Posts: 5
Joined: Sun Aug 31, 2014 12:32 pm

Re: 11572 - Unique Snowflakes

Post by incruator »

Please provide test cases for this.. I m stuck :( :(

Code: Select all

#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;

typedef vector<int>vi;
typedef pair<int,int>ii;
typedef vector<ii>vii;
#define M 1000000007
const int INF = (int) 1e9;
const int MAX = (int) 1e6 + 10;
set<ll>s;
//int a[MAX];
map<ll,ll>ma;
int main()
{
   // freopen("input.txt","r",stdin);
    ll t,n;
    scanf("%lld",&t);
    while(t--)
    {
        s.clear();
        ma.clear();
        scanf("%lld",&n);
        ll ans=0,mx=0,k;
        for(int i=0;i<n;i++)
        {
            scanf("%lld",&k);
            if(s.find(k)==s.end())
            {
               ma[k] =i;
               s.insert(k);
               ans++;
            }
            else
            {
                ll y=ma[k];
                ma[k]=i;
                mx=max(mx,ans);
                ans=(ans>(i-y)) ? (i-y) : ans;
            }
        }
        mx=max(ans,mx);
        cout<<mx<<endl;
    }

    return 0;
    }
RedGreenCode
New poster
Posts: 7
Joined: Wed May 13, 2015 3:41 am
Location: Seattle, WA, USA
Contact:

Re: 11572 - Unique Snowflakes

Post by RedGreenCode »

It took me a while to get a working (and sufficiently fast) solution to this one, so I wrote an editorial on it once I got my code accepted: http://www.redgreencode.com/uva-11572-u ... nowflakes/
Deliberate practice techniques for software developers -- http://www.redgreencode.com/
Post Reply

Return to “Volume 115 (11500-11599)”