CodeChef is a non-commercial competitive programming community
Login
Username (New User? Signup) Password (Forgot Password?)
Signup
Login or
Signup with
Connect
Note
  • Publicize your achievements on your Facebook Wall.
  • Challenge your friends or ask them for help.

Site Navigation

  • PRACTICE
    • Easy
    • Medium
    • Hard
    • Challenge
    • Peer
  • COMPETE
    • February CookOff
    • February Long Contest
    • January CookOff
  • DISCUSS
    • Wiki
    • Forums
    • Blog
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
    • Event Calendar
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Ranks
    • Tutorials
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Compete » August Mini Challenge 2009 (Contest VII) » Sudoku Solver

Sudoku Solver

Problem code: NSUDOKU

  • All Submissions

All submissions for this problem are available.

Quoting Wikipedia : "Sudoku is a logic-based, combinatorial number-placement puzzle. The objective is to fill a 9 9 grid so that each column, each row, and each of the nine 3 3 boxes (also called blocks or regions) contains the digits from 1 to 9 only one time each. The puzzle setter provides a partially completed grid." The rules for an N2 X N2 sudoku are as follows :

  • The board is consists of N2 rows and N2 columns.
  • Numbers between 1 and N2(inclusive) are to be filled in each row such that :
    • All numbers in each row are distinct.
    • All numbers in each column are distinct.
    • All numbers in the sub-matrix having rows from (i*N + 1) to(i + 1)*N, and columns from (j*N + 1) to (j + 1)*N both inclusive, should be distinct. 0 <= i,j <= N-1. Rows and columns are 1 indexed. Each such sub-matrix is called a "box" or "region".
For this problem, you are required to solve a general N2X N2 sudoku puzzle. Given a partially filled sudoku board, you have to fill it in as "perfect" a manner as possible.

Input :

The first line contains N,K. The following K lines contain 3 numbers: x, y and d. 1 <= x,y,d <= N^2. This means that a number d is present on the board at position (x,y) 2 <= N <= 30 0 <= K <= N4 At most 50% of the board will be covered at the start. All positions (x,y) in the input will be unique.

Output :

The output consists of N2 rows having N2 numbers each. Each number should be between 1 and N2 (inclusive) and separated by a space. If the initial grid has a number d at position (x,y), then even the output should have the number d at position (x,y).

Scoring :

  • For each row and every number K in the range 1 to N2 that is missing from the row, incurs a penalty of 1.
  • For each column and every number K in the range 1 to N2 that is missing from the column, incurs a penalty of 1.
  • Similary, for each box and every number K in the range 1 to N2 that is missing from the box, incurs a penalty of 1.
A box (as explained above) is a N X N square and the grid can be divided into N2 such non-overlapping boxes.

Example :

Input:

2 4
1 2 1
2 4 4
3 3 1
4 1 3

Output:

2 1 3 4
1 2 4 4
3 4 1 2
3 2 4 1

Penalty:

(0 + 1 + 0 + 0) + (1 + 1 + 1 + 1) + (2 + 2 + 1 + 1) = 11


Date: 2009-08-11
Time limit: 3s
Source limit: 50000
Languages: C C99 strict C++ PAS gpc PAS fpc JAVA NICE JAR C# C#2 NEM ST ASM D FORT ADA BASH PERL PYTH RUBY LUA ICON PIKE PHP SCM guile SCM qobi LISP sbcl LISP clisp SCALA HASK CAML CLPS PRLG WSPC BF ICK


  • Submit

Comments

  • Login or Register to post a comment.

Scoring doesn't seem to be

triplem @ 22 Aug 2009 03:25 PM

Scoring doesn't seem to be working.

Will the codes submitted for

keshav_57 @ 22 Aug 2009 03:28 PM
Will the codes submitted for this contest be made publicly available at the end of the contest?

@Keshav Yes. @Stephen Could

admin @ 22 Aug 2009 03:41 PM

@Keshav Yes.

@Stephen Could you be more specific ?

Unless I've misread something

triplem @ 22 Aug 2009 03:44 PM

Unless I've misread something somewhere, this was going to function exactly like the challenge problem in other contests - but I don't see what score I got for my accepted solution. Will the scores for each submission be completely private until the end of the contest?

We are looking into this.

admin @ 22 Aug 2009 03:48 PM

We are looking into this. There is no problem with the scoring as such, the only problem is that it's not getting displayed. Will be fixed soon.

scoring is not visible

moiezg @ 22 Aug 2009 04:13 PM
scoring is not visible

Is it possible, that given

keshav_57 @ 22 Aug 2009 04:17 PM
Is it possible, that given valid reasons and justification, you will re-consider the decision of making codes publicly available for this contest?

hey i got a compiler error

ankit4284 @ 22 Aug 2009 04:22 PM
hey i got a compiler error but in my own compiler i am not getting any error

@Ankit Check out

admin @ 22 Aug 2009 04:33 PM

@Ankit Check out www.codechef.com/help for information related to a sample submission in your language. Also check the FAQ.

 

@Keshav We are all ears. You can mail us why you think we should not make codes publicly available at admin@codechef.com

What should be the name of my

rohitpuri89 @ 22 Aug 2009 05:01 PM
What should be the name of my main class for Java compiler

www.codechef.com/help

admin @ 22 Aug 2009 05:06 PM

www.codechef.com/help

Is it possible that a penalty

keshav_57 @ 22 Aug 2009 05:39 PM
Is it possible that a penalty of 0 is impossible to achieve for a certain test case. That is, there does not exist any 'correct' solution for the given input. Or that the input itself violates one of more of the rules of Sudoku.

@ Keshav : Just like it wasnt

syco @ 22 Aug 2009 05:54 PM
@ Keshav : Just like it wasnt possible to achieve 0 penalty in the previous tie breakers, its very much possible that you cant do that here as well. The "conflicts" in the input will be faced by everyone though, so it doesnt change anything.

I am new here.So may be i

shklnrj @ 22 Aug 2009 06:00 PM
I am new here.So may be i might have misinterpreted the problem. But if in this problem we really need to solve a Sudoku , we need to have correct input too.The sample input provided in the problem will never have a 100% correct solution because the input of two 1's in the first and third row will force the output to be only partially correct. Is the solution to the problem checked on the basis of sample input here on Codechef??

@niraj Everyone gets the same

admin @ 22 Aug 2009 06:05 PM

@niraj Everyone gets the same input. As such, the initial penalty faced by everyone would be the same. This is not necessarily Sudoku in the most traditional form.

Is there any per day limit on

saeed @ 22 Aug 2009 06:18 PM
Is there any per day limit on number of submissions?

no

admin @ 22 Aug 2009 06:21 PM

no

How are the scores

neal @ 22 Aug 2009 06:27 PM
How are the scores accumulated over all test cases? (How is it that non-integer scores are showing up in the results?)

@Neal : Its total

syco @ 22 Aug 2009 06:29 PM
@Neal : Its total score/number of input files

Do we have read the input

deepakagrawal @ 22 Aug 2009 06:48 PM
Do we have read the input from some file? How should my program give the output(write to a file or prints on console)?

Input and output is done via

admin @ 22 Aug 2009 06:52 PM

Input and output is done via console. You have to read from the standard input (stdin) and the output should go to standard output (stdout)

What does the time column

anoopsabir @ 22 Aug 2009 08:33 PM
What does the time column indicate in my submissions and successful ones? What is the significance of the 3 sec time limit? Is it for one particular test case and the other one for total time elapsed?

What are the memory

khufiya @ 22 Aug 2009 11:07 PM
What are the memory constraints?

For some reason I'm receiving

neal @ 23 Aug 2009 12:16 AM
For some reason I'm receiving compile error when I submit, even though my program compiles fine on my computer (gcc 4.3.3), and there doesn't seem to be a place where I can view the exact error ("My Submissions" did not give me any information).

@Anoop There are multiple

admin @ 23 Aug 2009 01:12 AM

@Anoop There are multiple test cases. For each test case, the time limit is 3 seconds. The time shown in the time column is the sum of the times taken for each test case. If your program exceeds the 3 second time limit for any test case, then you would get a Time Limit Exceeded error.

 

@Rahul The judge guarantees 64 MB of memory for a submission

 

@Neal Are you still getting a compile error? It seems this has been sorted out. Mail us the submission id at admin@codechef.com if you continue to get a compile error.

What constitutes a wrong

gfosco @ 23 Aug 2009 07:17 AM
What constitutes a wrong answer?.. I submitted a test expecting a high penalty but at least successful execution.

When you do not follow the

syco @ 23 Aug 2009 07:55 AM
When you do not follow the output specifications, you get a WA.

Yeah, but I am following the

gfosco @ 23 Aug 2009 09:36 AM
Yeah, but I am following the output specs perfectly. N^2 lines each with N^2 spaced numbers between 1 and N^2 inclusive, with the given input numbers in the right spot. I've verified many cases up to and including N = 30.

Well, there have been enough

triplem @ 23 Aug 2009 10:27 AM

Well, there have been enough accepted solutions to imply it isn't something wrong with the judge, you must be doing something wrong. Perhaps mixing up rows/columns with the given input numbers.

It's kind of funny... the

gfosco @ 23 Aug 2009 11:14 AM
It's kind of funny... the same exact logical process: Times out in PHP and C#, produces a Wrong Answer in Pascal, but works fine in C.

Mere input/output and

anoopsabir @ 23 Aug 2009 12:57 PM
Mere input/output and declaration is getting me time out.

@Admin: What's the problem?

anoopsabir @ 23 Aug 2009 01:42 PM
@Admin: What's the problem?

@Anoop You probably need

admin @ 23 Aug 2009 06:02 PM

@Anoop You probably need faster input / output in your language.

Unlike the previous contest I

imrankane2005 @ 23 Aug 2009 09:33 PM
Unlike the previous contest I couldn't view my submitted solution through "My submission" button. is there any other way to view own submitted solution, other then view all submission and then find your's(at which there's a link to view own solution) which is also time taking

Are the prizes mentioned

sivaraman @ 23 Aug 2009 11:45 PM
Are the prizes mentioned only for students or for any professional?

@Imran This will be fixed

admin @ 24 Aug 2009 12:47 AM

@Imran This will be fixed before the next contest.

@sivaraman The contest is open to all.

whats the time limit for this

vinod @ 24 Aug 2009 06:16 AM
whats the time limit for this contest?

When does the contest end?

vinod @ 24 Aug 2009 06:21 AM
When does the contest end?

ends 530 US Eastern Time

gfosco @ 24 Aug 2009 06:33 AM
ends 530 US Eastern Time Monday Morning 8/24. US Eastern is GMT - 5.

Well fought, Anshuman :)

triplem @ 24 Aug 2009 03:04 PM

Well fought, Anshuman :)

@Stephen Thanks. You were

anshuman_singh @ 24 Aug 2009 03:12 PM
@Stephen Thanks. You were impressive, as always :)

@Admin: when will the

caesar @ 24 Aug 2009 09:05 PM
@Admin: when will the solutions be made available?

Tomorrow.

admin @ 24 Aug 2009 09:17 PM

Tomorrow.

who all are eligible to view

nishantb @ 25 Aug 2009 04:31 PM
who all are eligible to view the solutions??

Hey i am eager to view the

nishantb @ 25 Aug 2009 05:17 PM
Hey i am eager to view the solution plz reply...

hey why are the solutions to

ankit4284 @ 25 Aug 2009 09:04 PM
hey why are the solutions to the problems not public

That is what i am asking..no

nishantb @ 26 Aug 2009 09:20 AM
That is what i am asking..no one has replied till now

@Admin: why are the solutions

caesar @ 26 Aug 2009 12:59 PM
@Admin: why are the solutions not public yet even though the "View solution" link is up????????

Sorry for the delay. This is

admin @ 26 Aug 2009 02:10 PM

Sorry for the delay. This is now fixed.

How is the score shown with

anoopsabir @ 28 Aug 2009 01:38 PM

How is the score shown with the tick mark calculated?

It is the sum of the

admin @ 28 Aug 2009 01:50 PM

It is the sum of the penalties for the different test cases.

@Admin: Then how come it is a

anoopsabir @ 28 Aug 2009 02:23 PM

@Admin: Then how come it is a fraction?

Sorry for that, it is the

admin @ 28 Aug 2009 02:30 PM

Sorry for that, it is the average of the scores for the different test cases.

#include<stdio.h> main() {

gopikrish2000 @ 5 Sep 2009 05:42 PM

#include<stdio.h>

main()

{ int a=10;

 int b =20;

 int c;

 c= a+b;

printf("%d",c);

}

yes thanks stephen very

jeff474 @ 9 Jan 2010 01:04 PM

yes thanks stephen very impressive :)

____________________

sudoku solver developer sudoku solver solve sudoku instantly

SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:

Programming Competition Fetching successful submissions
Directi Go for Gold
CodeChef is a global programming communityCodeChef hosts online programming competitions
CodeChef is a non-commercial competitive programming community
  • About CodeChef
  • About Directi
  • CEO's Corner
  • C-Programming
  • Programming Languages
  • Contact Us
© 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs
In order to report copyright violations of any kind, send in an email to copyright@codechef.com
CodeChef a product of Directi
The time now is:
CodeChef - A Platform for Aspiring Programmers

CodeChef was created as a platform to help programmers make it big in the world of computer programming. At CodeChef we work hard to revive the geek in you by hosting programming contests on a monthly basis. We also aim to have training sessions and events related to online programming for programmers around the world. Apart from providing a platform for programming competitions, CodeChef also has various tutorials and forum discussions to help those who are new to the world of computer programming.

Practice Section - A Place to hone your 'Computer Programming Skills'

Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our judge accepts solutions in over 35+ programming languages. Online programming was never this much fun! Receive points, and move up through the CodeChef ranks. Use our practice section to better prepare yourself for the multiple programming competitions that take place through-out the month on CodeChef.

Compete - Monthly Programming Contests and Cook-offs

Here is where you can show off your computer programming skills. Take part in our 10 day long monthly programming contests and the shorter format Cook-off programming contests. Put yourself up for recognition and win great prizes. Prizes worth up to Rs.20,000 and $700 are up for grabs every month along with lots more CodeChef goodies.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be part of CodeChefs Forums and interact with all our programmers love helping out other programmers and share their ideas.

CodeChef Community

As part of our Educational initiative, we give institutes the opportunity to associate with CodeChef in the form of Campus Chapters. Hosting online programming competitions is not the only feature on CodeChef. Be a part of the CodeChef community through CodeChef meetups and techtalks. You can also host a programming contest for your institute on CodeChef and be a guest author on our blog.

Domain Name Registration, Web hosting, and Website Design provided by BigRock.com