Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
#include
#include
#include
#include
using namespace std; int main() { int h1, m1, h2, m2; cin >> h1 >> m1; cin >> h2 >> m2; int di[] = {-1, 1, 0, 0}; int dj[] = {0, 0, -1, 1}; bool visited[24][60]; memset(visited, false, sizeof visited); visited[h1][m1] = true; queue
q; q.push(h1); q.push(m1); q.push(0); while(!q.empty()) { int ch = q.front(); q.pop(); int cm = q.front(); q.pop(); int buttons_clicked = q.front(); q.pop(); if(ch == h2 and cm == m2) { cout << buttons_clicked << endl; return 0; } for(int k = 0; k < 4; k++) { int th = ch + di[k]; int tm = cm + dj[k]; if(tm == 60) { tm = 0; th++; } if(tm == -1) { tm = 59; th--; } if(th == 24) { th = 0; } if(th == -1) { th = 23; } if(!visited[th][tm]) { visited[th][tm] = true; q.push(th); q.push(tm); q.push(buttons_clicked + 1); } } } return 0; } // 00:00 - 23:59 // 00:00 --> 00:59
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)